08_NestedScrollView嵌套Recyclerview的问题

不管是 NestedScrollView 嵌套 Recyclerview 或其它可滑动的控件之间相互嵌套都会出现一些问题。

问题1. 滑动界面出现卡顿


解决办法:可以对嵌套的可滑动布局进行代码设置 setVerticalScrollBarEnabled(false) 方法,关闭它的可滑动的功能。以 Recyclerview 为例

recyclerView.setVerticalScrollBarEnabled(false);

问题2. 嵌套布局的抢焦点的问题


在使用前套布局后,打开界面,有时会出现界面自动往上移动了一部分,而让嵌套的可滑动布局完全显示在界面上。

解决办法:对外层的嵌套控件的父类容器添加 android:descendantFocusability="blocksDescendants" 属性。

...
// 嵌套布局的父类容器
<LinearLayout
        android:descendantFocusability="blocksDescendants"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/handle_rv"
                    android:background="@color/white"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:paddingBottom="20dp"/>

        </android.support.v4.widget.NestedScrollView>
    </LinearLayout>
...
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容