gpt4 book ai didi

android - 向上滚动时 StaggeredGridLayout 困惑

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:43:32 24 4
gpt4 key购买 nike

我为我的 RecyclerView 制作了这个 StaggeredGridLayout: enter image description here

代码如下:

 @Override
public 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, mContext));
titleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 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, mContext));
titleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15.00f);
subTitleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10.00f);
userImageOverlay.setVisibility(View.GONE);
}
}

一切正常,除非我向上滚动它。它按位置降序绘制单元格,并在网格中留下空白空间:

enter image description here

有什么想法即使向上滚动也能保持相同的模式吗?

最佳答案

试试这个:

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

关于android - 向上滚动时 StaggeredGridLayout 困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32311888/

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