我的Staggered Gridview布局存在一个带有滚动的差距问题。我在这个gridview中使用分页。如果我滚动继续上下,然后我滚动顶部的间隙。
活动代码
staggeredGridLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
staggeredGridLayoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE);
search_recyclear_view.setLayoutManager(staggeredGridLayoutManager);
ScrollListener
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();
}
ImageAdapter
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);
提前致谢。
答案 0 :(得分:0)
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