当前位置:网站首页>横向滚动的RecycleView一屏显示五个半,低于五个平均分布

横向滚动的RecycleView一屏显示五个半,低于五个平均分布

2022-07-05 09:41:00 沙漠一只雕得儿得儿

    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View itemView = mInflater.inflate(R.layout.layout_item_hq_cn_icon, parent, false);

        int columnWidth;
        if (mDataSet.size() > 5) {
            columnWidth = (int) (parent.getMeasuredWidth() / 5.57f);
        } else {
            columnWidth = (int) (parent.getMeasuredWidth() / mDataSet.size());
        }

        RecyclerView.LayoutParams lp = new RecyclerView.LayoutParams(columnWidth, RecyclerView.LayoutParams.WRAP_CONTENT);
        itemView.setLayoutParams(lp);
        return ViewHolder.createViewHolder(mContext, itemView);
    }

原网站

版权声明
本文为[沙漠一只雕得儿得儿]所创,转载请带上原文链接,感谢
https://buder.blog.csdn.net/article/details/125405134