android解决RecyclerView嵌套在NestedSc

作者: 陈先森_a238 | 来源:发表于2019-10-25 17:54 被阅读0次

    android解决RecyclerView嵌套在NestedScrollView中在解决滑动冲突问题后出现子项显示不全的问题。

    1.解决滑动冲突的问题在代码中下入:

    recycler.setHasFixedSize(true);

    recycler.setNestedScrollingEnabled(false);

    但是会出现recyclerview的子项显示不全的问题,这时候只需要在布局中:

    <android.support.v4.widget.NestedScrollView

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        android:fillViewport="true">

    <RelativeLayout

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:descendantFocusability="blocksDescendants">

    <android.support.v7.widget.RecyclerView

                android:id="@+id/rv_data_list"

                android:layout_width="match_parent"

                android:layout_height="match_parent"

                android:overScrollMode="never" />

    如上给RecyclerView和NestedScrollView之间给RecyclerView加一层父布局,但是这个父布局只能是RelativeLayout,而不能用比较新的ConstraintLayout,

    然后在RelativeLayout加入 android:descendantFocusability="blocksDescendants"即可。

    相关文章

      网友评论

        本文标题:android解决RecyclerView嵌套在NestedSc

        本文链接:https://www.haomeiwen.com/subject/uakevctx.html