如何在LinearLayoutManager-RecyclerView中重叠项目(例如堆叠卡) [英] How to Overlap items in LinearLayoutManager - RecyclerView (like stacking cards)

查看:527
本文介绍了如何在LinearLayoutManager-RecyclerView中重叠项目(例如堆叠卡)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


是否有可能与RecyclerView中的项目重叠?
我正在尝试使用LinearLayoutManager.
我的要求与LinearLayoutManager中的要求相同,我只需要从上到下重叠内部的项目. (例如堆叠卡)


Is that possible to overlap the items from RecyclerView ?
I am trying that with LinearLayoutManager.
My requirements are just the same as in LinearLayoutManager and I just need to overlap the items inside from top to bottom. (like stacking cards)

我已经通过使用ListView看到了一些变体.所以,我认为 也可以在RecyclerView中使用.但是,经过一段时间的探索, 我觉得实施自定义功能需要花费很多时间 布局经理,对此有相当的了解.(我看着 进入Dave关于构建自定义LayoutManager 的帖子)

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变体,而不是处理如此复杂的自定义布局管理器".

So, now I am thinking I might just need to use ListView variation based on my requirement instead of dealing with this much complexity of Custom Layout Manager.

但是,我只需要使内部的项目重叠即可.我觉得可能还有其他我还不知道的方向.请告诉我,除了ListView变量上方的 自定义布局管理器之外.

But, I just need to make the items inside to overlap. I feel like there might be some other direction that I haven't aware yet. Pls let me know if there is any apart from above ListView varient and Custom Layout Manager.

我还将在下面发布我的发现.

I will also post my findings below here.

推荐答案

我假设您正在寻找部分重叠(例如,纸牌稍微散开).如果是这样,使用RecyclerView和自定义ItemDecoration似乎很简单.这是一个平凡的示例,其中的项目在垂直方向上重叠了90px:

I assume you're looking for a partial overlap (e.g. deck of cards slightly fanned out). If so, this seems fairly simple with RecyclerView and a custom ItemDecoration. Here's a trivial example of one that overlaps the items by 90px vertically:

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);

  }
}

此示例对偏移量进行了硬编码,但是如果列表项的高度不同,则需要为此测量并添加逻辑.

This example hard codes the offset, but if your list items vary in height you'll need to measure and add logic for this.

在设置layoutmanager之前,将此装饰添加到RV.我已经用StaggeredGrid进行了尝试,但是它也应该与LinearLayout和Grid LM一起使用.

Add this decoration to the RV before setting the layoutmanager. I've tried it with a StaggeredGrid but it should work with LinearLayout and Grid LM's as well.

这篇关于如何在LinearLayoutManager-RecyclerView中重叠项目(例如堆叠卡)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆