match_parent width does not work in RecyclerView

后端 未结 10 1448
深忆病人
深忆病人 2020-11-27 13:25

My RecyclerView and item has match_parent width but the result is : \"enter

           


        
10条回答
  •  广开言路
    2020-11-27 13:50

    This worked for me.

    replace this

       View view = View.inflate(parent.getContext(), R.layout.row_timeline, null);
       return new TimeLineViewHolder(view, viewType);
    

    by this

     View rootView = LayoutInflater.from(context).inflate(R.layout.row_timeline, null, false);
            RecyclerView.LayoutParams lp = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            rootView.setLayoutParams(lp);
            return new TimeLineViewHolder(rootView, viewType);
    

提交回复
热议问题