Android 关于RecycleView瀑布流item换位

项目需要使用瀑布流,看了下感觉还挺容易,结果上下滑动的时候遇到item换位问题
<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/mRecyc"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    />
看了别人的解决方法,结果还是不行,最后才发现,是我把recycleview高度设成了wrap_content

附带解决方法

//声明瀑布流的布局方式: 2列,垂直方向
StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
//为recyclerView设置布局管理器
mRecyc.setLayoutManager(staggeredGridLayoutManager);

staggeredGridLayoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE);

在adapter内,

Map<Integer, Integer> heightArray = new HashMap<>();使用map保存已加载的view的高度
if (heightArray.get(i) == null) {
    int height = 0;  

    ConstraintLayout.LayoutParams imageParams = (ConstraintLayout.LayoutParams) secKillViewHolder.mImage_video.getLayoutParams();
    imageParams.height = height;
    secKillViewHo
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值