Android开发经验谈Android技术知识Android开发

android解决RecyclerView嵌套在NestedSc

2019-10-25  本文已影响0人  陈先森_a238

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"即可。

上一篇下一篇

猜你喜欢

热点阅读