我在nestedScrollView中布置RecyclerView,并希望使用RecyclerView进行nestedScrollView滚动,但只有在recyclelerView达到最后才会发生,下面是我的布局代码:
<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>
这是我的运行时视图:
解决方法
<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应用于recyclelerview并将其设置为false
P.s:for Api lower 21:
ViewCompat.setnestedScrollingEnabled(recyclelerView,false);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。