1. 程式人生 > >RecyclerView的item寬度不能全屏顯示

RecyclerView的item寬度不能全屏顯示

錯誤寫法:

@Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_complain_list, null, false);
        view.setOnClickListener(this);
        return new ViewHolder(view);
    }

正確寫法:

@Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_complain_list, parent
, false); view.setOnClickListener(this); return new ViewHolder(view); }

此處傳入的parent即為item的根佈局