是否可以与 RecyclerView 中的项目重叠?
我正在尝试使用 LinearLayoutManager。
我的要求与 LinearLayoutManager 中的要求相同,只需将内部的项目从上到下重叠即可。 (如堆叠卡片)
I have seen some variant by using ListView. So, I figure it would be possible in RecyclerView too.But, after some times of exploration, I feel like its gonna take quite some time to implement a custom layout manager and quite an extent of understanding on this.(I looked into Dave's post about Building Custom LayoutManager )
所以,现在我想我可能只需要根据我的要求使用 ListView 变体,而不是处理如此复杂的自定义布局管理器。
但是,我只需要让里面的项目重叠。我觉得可能还有其他一些我还没有意识到的方向。请让我知道是否有任何除了上面的 ListView 变体和自定义布局管理器。
I will also post my findings below here.
最佳答案
我假设您正在寻找部分重叠(例如,一副稍微散开的纸牌)。如果是这样,使用 RecyclerView 和自定义 ItemDecoration 似乎相当简单。这是一个将项目垂直重叠 90 像素的简单示例:
public class OverlapDecoration extends RecyclerView.ItemDecoration {
private final static int vertOverlap = -90;
@Override
public void getItemOffsets (Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
outRect.set(0, vertOverlap, 0, 0);
}
}
此示例对偏移量进行硬编码,但如果您的列表项的高度不同,您需要为此测量并添加逻辑。
在设置布局管理器之前将此装饰添加到 RV。我已经尝试使用 StaggeredGrid,但它也应该适用于 LinearLayout 和 Grid LM。
关于android - 如何在 LinearLayoutManager 中重叠项目 - RecyclerView(如堆叠卡片),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27633454/