我正在尝试实现一个在同一布局中包含RecyclerView和ScrollView的布局。
布局模板:
<RelativeLayout>
<ScrollView android:id="@+id/myScrollView">
<unrelated data>...</unrealated data>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/my_recycler_view"
/>
</ScrollView>
</RelativeLayout>
问题:我可以滚动到ScrollView
的最后一个元素
我尝试过的事情:
ScrollView
内部的卡片视图(现在ScrollView
包含RecyclerView
) -在RecyclerView
RecyclerView
而不是ScrollView
来实现这个viewGroup
之前,我可以看到卡片,其中一个视图类型是CardView
,但是我得到了与same完全相同的结果发布于 2016-05-20 13:42:12
使用NestedScrollView
而不是ScrollView
请通过NestedScrollView reference document了解更多信息。
并向您的RecyclerView
添加recyclerView.setNestedScrollingEnabled(false);
发布于 2016-08-17 19:29:19
我知道我来晚了,但即使在谷歌修复了android.support.v7.widget.RecyclerView
之后,这个问题仍然存在
我现在得到的问题是RecyclerView
与layout_height=wrap_content
没有采取高度的ScrollView
内部的所有项目的问题,只有发生在棉花糖和Nougat+ (API23,24,25)版本。
(更新:用android.support.v4.widget.NestedScrollView
替换ScrollView
在所有版本上都有效。不知何故,我错过了对的测试。将其作为演示添加到我的github项目中。)
在尝试了不同的方法之后,我找到了解决此问题的方法。
下面是我的布局结构:
<ScrollView>
<LinearLayout> (vertical - this is the only child of scrollview)
<SomeViews>
<RecyclerView> (layout_height=wrap_content)
<SomeOtherViews>
解决方法是使用RelativeLayout
包装RecyclerView
。不要问我是如何找到此解决方法的!¯\_(ツ)_/¯
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
在GitHub项目- https://github.com/amardeshbd/android-recycler-view-wrap-content上提供了完整的示例
这是一个演示屏幕视频,展示了修复的实际操作:
发布于 2015-02-13 19:08:03
尽管建议
永远不应该将可滚动视图放在另一个可滚动视图中
是一个合理的建议,但是如果你在回收器视图上设置一个固定的高度,它应该可以很好地工作。
如果您知道适配器项布局的高度,您可以只计算RecyclerView的高度。
int viewHeight = adapterItemSize * adapterData.size();
recyclerView.getLayoutParams().height = viewHeight;
https://stackoverflow.com/questions/27083091
复制相似问题