问题描述
我正在尝试在其中的RecyclerView
父级中创建一个混合项,其中包含一些CardViews
并在其中包含另一个RecyclerView
.如果还看不到,请想象RecyclerView
中有几个ListViews
(ListViews
由标题分组).
I'm trying to create a mixed items in a RecyclerView
parent, within it, contains some CardViews
with another RecyclerView
inside it. If you can't see it yet, imagine several ListViews
inside a RecyclerView
(with the ListViews
being grouped by a Header).
这里是我为了使其更清晰而绘制的结构:
Here is a structure that I've drawn to make it more clear:
以上是我要实现的布局结构.请注意,这仅是计划.我不确定将RecyclerView包含在RecyclerView中是否是一个好主意.
Above is the layout structure that I'm trying to achieve. Please note that this is only the planning. I'm not sure if it is a good idea to have a RecyclerView within a RecyclerView.
到目前为止,我已经尝试使用 ExpandableRecyclerView 来实现这种复杂的布局.但是问题是,当在RecyclerView中添加其他项目类型时(例如,水平滚动轮播),它会隐藏在Header中.
So far, I've tried using ExpandableRecyclerView to achieve this kind of complex layout. But the problem is when adding a different item type in the RecyclerView (eg. a horizontal scroll carousel), it is hidden within the Header.
我现在想不出其他任何方式.你们对如何实现这种布局有什么建议吗?
I can't think of any other ways now. Do you guys have any suggestions on how to achieve this layout?
为简单起见,如果您理解我的意思,它是RecyclerView
父级中子CardView
中的RecyclerView
部分.
To make it simple, it is a sectioned RecyclerView
within a child CardView
inside a RecyclerView
parent, if you understand what I mean.
推荐答案
不建议在另一个RecyclerView中使用RecyclerView.但是,如果您想使用嵌套的RecyclerViews实现上述目的,则可以使用布局管理器,将最里面(绿色)的RecyclerView包裹RecyclerView到其内容的高度.在 https://github.com/serso/android-线性布局管理器
Having a RecyclerView within another RecyclerView is discouraged. However if you want to achieve the above using nested RecyclerViews, you can use a layout manager that wraps the RecyclerView to its content's height for the innermost (Green Coloured) RecyclerView. There is one such layout manager already available at https://github.com/serso/android-linear-layout-manager
还请确保通过如下设置onTouchListener来禁用最里面的RecyclerView上的触摸手势.
Also make sure to disable touch gestures on the innermost RecyclerView by setting an onTouchListener as follows.
mRecyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener {
@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
return true;
}
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
}
@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
}
});
这篇关于另一个RecyclerView中的RecyclerView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!