ScrollView里嵌套Recycleview使用StaggeredGridLayoutManager高度不正确的问题

博客介绍了如何解决ScrollView内嵌RecyclerView,当使用StaggeredGridLayoutManager时高度计算不准确的问题。文章补充了在LinearLayoutManager和GridLayoutManager基础上,针对StaggeredGridLayoutManager的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://frank-zhu.github.io/android/2015/02/26/android-recyclerview-part-3/

作者的这个文章中给出了ScrollView中嵌套Recycleview使用LinearLayoutManager和GridLayoutManager重写高度的方法,但是没有StaggeredGridLayoutManager的重写高度。

在此补充,已备后用

public class MyStaggeredGridLayoutManager extends StaggeredGridLayoutManager {


    public MyStaggeredGridLayoutManager(int spanCount, int orientation, Context mContext) {
        super(spanCount, orientation);
        mHeightArray = new int[spanCount];
        this.mContext = mContext;
        for (int i = 0; i < spanCount; i++)
            mHeightArray[i] = 0;
    }

    private int[] mMeasuredDimension = new int[2];
    private int[] mHeightArray;
    private Context mContext;

    @Override
    public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state, int widthSpec, int heightSpec) {
        final int widthMode = View.MeasureSpec.getMode(widt
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值