【问题标题】:NestedScrollView scroll with recyclerviewNestedScrollView 滚动与 recyclerview
【发布时间】:2015-09-11 21:57:32
【问题描述】:

我在NestedScrollView 中布局RecyclerView,我想让NestedScrollView 滚动与RecyclerView,但这仅在recyclerView 到达末尾时发生,下面是我的布局代码:

<android.support.v4.widget.NestedScrollView
android:id="@+id/lists_frame"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
tools:context="com.example.niuky.design.MainActivity4"
>
    <LinearLayout
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical"
   >
    <View
       android:id="@+id/header"
       android:layout_width="match_parent"
       android:layout_height="256dp"
       android:background="@color/material_blue_grey_800"
       />

   <View
       android:id="@+id/tabs"
       android:layout_width="match_parent"
       android:layout_height="?android:attr/actionBarSize"
       android:background="@color/material_blue_grey_950"
       />

  <android.support.v7.widget.RecyclerView
      android:id="@+id/recyclerview2"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:minHeight="700dp"

      />
   </LinearLayout>
</android.support.v4.widget.NestedScrollView>

这是我的运行时视图:

【问题讨论】:

  • 您为什么不使用支持CoordinatorLayoutAppBarLayoutNestedScrollView 来代替?
  • @tato.rodrigo 首先我使用CoordinatorLayout AppBarLayout 但我无法得到我想要的。你有什么想法吗?非常感谢!
  • @tato.rodrigo 如果我们不想使用设计支持库怎么办? NestedScrollView 应该允许我们做这样的事情......但是,正如谷歌最近习惯的那样,根本没有文档。
  • @acntwww 嗨,我现在遇到了同样的问题,您找到解决此问题的方法了吗? :)

标签: android scrollview android-recyclerview


【解决方案1】:

在 RecyclerView 上android:nestedScrollingEnabled="false"

【讨论】:

    【解决方案2】:
    <android.support.v4.widget.NestedScrollView
        android:id="@+id/nested_scrollbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="fill_vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:scrollbars="none" >
            <LinearLayout
                android:id="@+id/nested_scrollbar_linear"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" >
    
                    <android.support.v7.widget.CardView
                        android:id="@+id/flexible.example.cardview"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">
    
                    </android.support.v7.widget.CardView>
    
                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/list_view"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    
        </LinearLayout>
    
    </android.support.v4.widget.NestedScrollView>
    

    并将.setNestedScrollingEnabled 应用于recyclerview 并将其设置为false

    P.s:对于 Api 低 21 位:

    ViewCompat.setNestedScrollingEnabled(recyclerView, false);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-11
      • 2019-05-25
      • 2016-03-19
      相关资源
      最近更新 更多