gpt4 book ai didi

android - 在 StaggeredGridLayoutManager 中设置单行的跨度大小

转载 作者:IT老高 更新时间:2023-10-28 22:04:44 25 4
gpt4 key购买 nike

我有一个有 2 列的交错网格。这是有效的。我想要的是在位置 0 使行跨越 2 列。我之前很容易使用 GridLayoutManger 做到了这一点:

                mGridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
return position == 0 ? 2 : 1;
}
});

StaggeredGridLayoutManager 不像 GridLayoutManager 那样为我提供此功能。

有没有其他方法可以做到这一点?我已经搜索但没有找到任何有相同问题的人,这令人惊讶,因为当 RecyclerView 的最后一行显示 ProgressBar 时,我认为此功能对我的场景和无限滚动非常有用。

最佳答案

您可以使用 setFullSpan方法。
这样,项目将使用所有跨度区域进行布局。

That means, if orientation is vertical, the view will have full width; if orientation is horizontal, the view will have full height.

类似这样的:

public final void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {

StaggeredGridLayoutManager.LayoutParams layoutParams = (StaggeredGridLayoutManager.LayoutParams) viewHolder.itemView.getLayoutParams();
layoutParams.setFullSpan(true);
}

注意。
它支持跨越所有列的 View ,但对于您的情况应该足够了。

关于android - 在 StaggeredGridLayoutManager 中设置单行的跨度大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33696096/

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