Recyclerview中的重叠位置/视图 [英] Overlap positions/views in recyclerview
问题描述
我一直试图在recyclerview中重叠两个相邻的位置,但是没有这样做.我希望第一位置的一部分重叠/绘制在第二位置上.
I've been trying to overlap two adjacent positions in a recyclerview, but fail to do so. I would like a part of the first position overlap/draw over the second position.
我一直在玩自定义RecyclerView.ItemDecoration,它是getItemOffsets,但是似乎只能在某个位置添加填充/边距,而不是将其转换为视图父级之外的新位置.
I've have been playing around with a custom RecyclerView.ItemDecoration and it's getItemOffsets, however that just seem to be able to add padding/margin on a position, not translating it to a new position outside it's viewparent.
有人知道如何通过recyclerview实现这一目标吗?
Anyone got any pointers of how to achieve this with a recyclerview?
推荐答案
好,您还可以在示例:
ItemDecorator.java
public class ItemDecorator extends RecyclerView.ItemDecoration {
private final int mSpace;
public ItemDecorator(int space) {
this.mSpace = space;
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
outRect.left = mSpace;
outRect.right = mSpace;
outRect.bottom = mSpace;
outRect.top = mSpace;
}
}
MainActivity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayList<String> arrayList = new ArrayList<>();
arrayList.add("Hi");
arrayList.add("World");
arrayList.add("What");
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.rec1);
//Negative margin!
ItemDecorator itemDecorator = new ItemDecorator(-30);
recyclerView.setAdapter(new CustomAdapter(arrayList));
recyclerView.addItemDecoration(itemDecorator);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
}
}
这篇关于Recyclerview中的重叠位置/视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!