我为我的RecyclerVIEw制作了这个StaggeredGrIDLayout:
这是代码:
@OverrIDepublic voID onBindVIEwHolder(RecyclerVIEw.VIEwHolder vIEwHolder,final int position) { Photo photo = mPhotos.get(position); TextVIEw TitleVIEw = ((CellVIEwHolder) vIEwHolder).TitleTextVIEw; TitleVIEw.setText(photo.getTitle()); TextVIEw subTitleVIEw = ((CellVIEwHolder) vIEwHolder).subTitleTextVIEw; subTitleVIEw.setText(photo.getname()); Picasso.with(mContext).load(photo.getPhotoUrl()).into(((CellVIEwHolder) vIEwHolder).imageVIEw); ImageVIEw userImageOverlay = ((CellVIEwHolder) vIEwHolder).userImageOverlay; StaggeredGrIDLayoutManager.LayoutParams layoutParams = (StaggeredGrIDLayoutManager.LayoutParams) vIEwHolder.itemVIEw.getLayoutParams(); if (position == 0 || position % 4 == 0) { layoutParams.setFullSpan(true); layoutParams.height = Math.round(Utils.convertDptopixel(202.67f,mContext)); TitleVIEw.setTextSize(TypedValue.COMPLEX_UNIT_SP,21.67f); subTitleVIEw.setTextSize(TypedValue.COMPLEX_UNIT_SP,12.00f); userImageOverlay.setVisibility(VIEw.VISIBLE); } else if ((position - 1) % 4 == 0) { layoutParams.setFullSpan(false); layoutParams.height = Math.round(Utils.convertDptopixel(360.00f,15.00f); subTitleVIEw.setTextSize(TypedValue.COMPLEX_UNIT_SP,10.00f); userImageOverlay.setVisibility(VIEw.GONE); } else { layoutParams.setFullSpan(false); layoutParams.height = Math.round(Utils.convertDptopixel(180.00f,10.00f); userImageOverlay.setVisibility(VIEw.GONE); }}
除非我将它向上滚动,否则一切正常.它按位置按降序绘制单元格,并在网格中留下空白区域:
任何想法如何保持相同的模式甚至滚动它?
@H_404_18@最佳答案@H_404_18@试试这个:StaggeredGrIDLayoutManager manager = new StaggeredGrIDLayoutManager(2,StaggeredGrIDLayoutManager.VERTICAL);manager.setGapStrategy(StaggeredGrIDLayoutManager.GAP_HANDliNG_MOVE_ITEMS_BETWEEN_SPANS);recyclerVIEw.setLayoutManager(manager);
或:change position when scrolling
或者:github项目Picasso/Glide-RecyclerView-StaggeredGridLayoutManager@H_404_18@ 总结
以上是内存溢出为你收集整理的android – StaggeredGridLayout在向上滚动时搞砸了全部内容,希望文章能够帮你解决android – StaggeredGridLayout在向上滚动时搞砸了所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)