当前位置:网站首页>橫向滾動的RecycleView一屏顯示五個半,低於五個平均分布

橫向滾動的RecycleView一屏顯示五個半,低於五個平均分布

2022-07-05 10:11: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://yzsam.com/2022/186/202207050941163334.html