设置recycleview子条目各占屏幕的比例

比如 1/3的比例

 @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view=LayoutInflater.from(mContext).inflate(R.layout.hot_show_recycle_item,viewGroup,false);

        DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
        int widthPixels = metrics.widthPixels;
        ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
        layoutParams.width=widthPixels/3;
        ViewHolder viewHolder=new ViewHolder(view);
        return viewHolder;
    }

你可能感兴趣的:(设置recycleview子条目各占屏幕的比例)