【问题标题】:ScrollView with nested RecyclerViews and bidirectional scroll具有嵌套 RecyclerViews 和双向滚动的 ScrollView
【发布时间】:2019-08-23 20:12:04
【问题描述】:

我想实现下图所示的效果

两个垂直滚动的列表视图,其中一个也可以水平滚动以显示更多内容。

我在 Google Discover 的一张卡片上看到了它,我想将它应用到我的一个项目中。 我可以尝试自己实现它,但由于它被 Google 使用,它可能已经可用,例如作为材料设计组件等。

到目前为止我找不到类似的东西。

【问题讨论】:

    标签: android android-recyclerview android-support-library nested-lists gridlayoutmanager


    【解决方案1】:

    最终用这个布局找到了解决办法。

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:overScrollMode="never">
    
       <LinearLayout
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:orientation="horizontal"
           android:weightSum="2">
    
           <android.support.v7.widget.RecyclerView
               android:id="@+id/left_recycler_view"
               android:layout_width="0dp"
               android:layout_height="wrap_content"
               android:nestedScrollingEnabled="false"
               android:layout_weight="1" />
    
           <HorizontalScrollView
               android:layout_width="0dp"
               android:layout_height="wrap_content"
               android:layout_weight="1">
    
               <android.support.v7.widget.RecyclerView
                   android:id="@+id/right_recycler_view"
                   android:layout_width="wrap_content"
                   android:nestedScrollingEnabled="false"
                   android:layout_height="wrap_content" />
    
           </HorizontalScrollView>
    
       </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
    

    两个回收站视图都有一个简单的LinearLayoutManager

    android:nestedScrollingEnabled="false" 仅从 API 21 开始可用,因此在其他情况下需要通过代码设置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-26
      相关资源
      最近更新 更多