【发布时间】:2016-03-22 17:57:55
【问题描述】:
我正在尝试在 ScrollView
中显示水平 recyclerview 项目和垂直 recyclerview 项目即使我使用 android:fillViewport="true"
,滚动视图也不起作用 <ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
//Horizontal Recyclerview items
<RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content">
</RecyclerView>
//vertical Recyclerview items
<RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"></RecyclerView>
</LinearLayout>
</ScrollView>
【问题讨论】:
-
您的布局可以简化。 ParentView 是
RecyclerView(垂直项目),索引 0 处的项目是另一个RecyclerView(水平项目)。 -
您应该必须使用一个子滚动视图,而您的 xml 的其他视图将在该子视图中。要使 recyclerView 与滚动视图一起使用,您必须在 xml 中为您的 recyclerview 提供 0dp 高度,并提供您的 recyclerview 在运行时可以采用的最大高度。在垂直 recyclerView 的情况下,您可以通过将总行数 * 一行的高度(以 dp 为单位)相乘来计算最大高度,而在水平方向上,您只能给出一个孩子的高度。就像我们有 10 个 40dp 的 textview,那么垂直 recyclerView 高度将是 10*40 dp = 400dp 和 10dp 水平。
-
你可以做到...看这里:link
-
为了将来参考,如果有人在
ScrollView中遇到RecyclerViewwrap_content 问题,仅发生在棉花糖/牛轧糖(API 23、24)设备上,请查看我的解决方法在stackoverflow.com/a/38995399/132121
标签: android android-recyclerview android-scrollview