리스트뷰 대신에 RecyclerView 를 이용하여 게시판을 만들어보려고 하고있는데


화면에서 분명히 RecyclerView의 width를 match_parrent로 하여 옆으로 꽉차게 하였는데


적용되지가 않았다 (물론 item도 width는 match_parrent)


////////////////////////////////////////////////////////


검색해보니 어댑터 부분의 onCreateViewHolder 부분을 수정해주면 된다고 하여 수정해보았다.


원래 아래와같이 


   @Override

    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_lost, null);

        return new ViewHolder(v);

    }


이런식으로 작성하였었는데 아래와 같이 작성하니



   @Override

    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_lost, parent, false);

        return new ViewHolder(v);

    }


해결되었다.


원인은 


Parameters
resource ID for an XML layout resource to load (e.g., R.layout.main_page) root
view to be the parent of the generated hierarchy (if attachToRoot is true), or else simply an object that provides a set of LayoutParams values for root of the returned hierarchy (if attachToRoot is false.)
attachToRoot Whether the inflated hierarchy should be attached to the root parameter? If false, root is only used to create the correct subclass of LayoutParams for the root view in the XML. Returns The root View of the inflated hierarchy. If root was supplied and attachToRoot is true, this is root; otherwise it is the root of the inflated XML file.


It is important here to not supply true, but do supply the parent:


Supplying the parent View lets the inflater know what layoutparams to use. Supplying the falseparameter tells it to not attach it to the parent just yet. That is what the RecyclerView will do for you.


요렇다는데 아직 이해가 안간다. 시간날때 다시 해석해봐야겠다

+ Recent posts