gpt4 book ai didi

android - 滚动在交错的 Gridview 中产生间隙

转载 作者:行者123 更新时间:2023-12-05 07:41:14 24 4
gpt4 key购买 nike

我的带滚动的交错 Gridview 布局存在间隙问题。我在这个 gridview 中使用分页。如果我继续向上和向下滚动,然后在我滚动到上面的间隙之后。

image causing Gap

Activity 代码

staggeredGridLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
staggeredGridLayoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE);
search_recyclear_view.setLayoutManager(staggeredGridLayoutManager);

滚动监听器

 search_recyclear_view.addOnScrollListener(new EndlessRecyclerOnScrollListener(staggeredGridLayoutManager) {
@Override
public void onLoadMore(int current_page) {
//for no gap use this
((StaggeredGridLayoutManager)search_recyclear_view.getLayoutManager()).invalidateSpanAssignments();
// do something...
getData();
}

图像适配器

 RelativeLayout.LayoutParams rlp = (RelativeLayout.LayoutParams) imageView.getLayoutParams();
rlp.height = (int) (rlp.width * item.getImage_ratio());
imageView.setLayoutParams(rlp);
imageView.setHeightRatio(item.getImage_ratio());
Picasso.with(mContext)
.load(baseuri + item.getImageName()).placeholder(PlaceHolderDrawableHelper.getBackgroundDrawable(position))
.into(imageView);

提前致谢。

最佳答案

StaggeredGridLayoutManager sGrid = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
sGrid.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS);

试试吧。

交错的网格很可能在布局的边缘有间隙。为了避免这些间隙,StaggeredGridLayoutManager 可以独立偏移跨度或在跨度之间移动项目。您可以通过 setGapStrategy(int) 控制此行为。

https://developer.android.com/reference/android/support/v7/widget/StaggeredGridLayoutManager.html

关于android - 滚动在交错的 Gridview 中产生间隙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45518891/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com