我有一个嵌套的纵向NestedScrollView,并包含一系列具有水平LayoutManager设置的RecyclerView。这个想法与新的Google Play商店看起来非常相似。虽然我能够使它运行,但它并不流畅。以下是问题:
1)水平RecyclerView项目大多数时候无法拦截触摸事件,即使我在它上面轻按。滚动视图似乎在大多数情况下都优先处理动作。对于我来说很难抓住水平动作。这种用户体验令人沮丧,因为我需要尝试几次才能使其正常工作。如果您检查Play商店,则能够非常好地拦截触摸事件,并且可以正常工作。我注意到,在商店中设置方式是许多水平RecyclerViews内部没有ScrollView。
2)必须手动设置水平RecyclerView的高度,并且没有简单的方法来计算子元素的高度。
以下是我使用的布局:
<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" />
这个用户界面模式非常基础,很可能在许多不同的应用程序中使用。我读了很多SO(Stack Overflow)上的帖子,人们说在列表内部放置另一个列表是一个不好的主意,但这是一个非常常见和现代的UI模式,广泛运用于各个领域。想象一下像Netflix那样的界面,垂直列表内有一系列水平滚动列表。是否有一种流畅的方法来实现这一点呢?
商店的示例图像: