【发布时间】:2016-03-19 10:18:57
【问题描述】:
我有一个垂直的nestedscrollview,其中包含一堆带有水平布局管理器设置的recyclerview。这个想法与新的 google play 商店的外观非常相似。我能够使其正常工作,但它一点也不流畅。以下是问题:
1) 即使我点击它,水平 recyclerview 项目大多数时候都无法拦截触摸事件。滚动视图似乎优先于大多数动作。我很难抓住水平运动。这个 UX 令人沮丧,因为我需要尝试几次才能正常工作。如果你查看 play store,它能够很好地拦截触摸事件,而且效果很好。我注意到在 Play Store 中,他们设置的方式是在一个垂直的 recyclerview 中有许多水平的 recyclerviews。没有滚动视图。
2) 水平recyclerviews的高度必须手动设置,并且没有简单的方法来计算子元素的高度。
这是我正在使用的布局:
<android.support.v4.widget.NestedScrollView
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:background="@color/dark_bgd"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/main_content_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
tools:visibility="gone"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/starring_list"
android:paddingLeft="@dimen/spacing_major"
android:paddingRight="@dimen/spacing_major"
android:layout_width="match_parent"
android:layout_height="180dp" />
这种 UI 模式非常基本,很可能在许多不同的应用程序中使用。我读过很多 SO,其中 ppl 说将列表放在列表中是一个坏主意,但它是一种非常常见且现代的 UI 模式,到处都在使用。想想 netflix 之类的界面,里面有一系列水平滚动列表一个垂直列表。难道没有一种顺利的方法可以做到这一点吗?
来自商店的示例图片:
【问题讨论】:
-
奇怪的是我有相反的问题:我希望 NestedScrollView 允许垂直滚动,但水平 RecyclerView 需要触摸事件,所以当我开始垂直滚动时,它不会允许它。另外,顺便说一句,如果您只有几个项目要显示,您可以使用带有 LinearLayout 的简单 HorizontalScrollView。
标签: android android-recyclerview horizontal-scrolling nestedscrollview