NestedScrollView中嵌套ViewPager或RecyclerView出现滑动冲突的解决

NestedScrollView嵌套ViewPager出现的滑动冲突

  • 问题描述:
    ViewPager无法左右滑动, 切无内容显示. 如果有相关Tab与ViewPager相绑定, 会导致Tab切换卡顿.

  • 问题布局复原:

   <android.support.v4.widget.NestedScrollView
        android:id="@+id/home_scroll_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v4.view.ViewPager
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

    </android.support.v4.widget.NestedScrollView>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 解决办法:
    在相应Activity或Fragment中
NestedScrollView nestedScrollView = view.findViewById(R.id.home_scroll_view);
nestedScrollView.setFillViewport(true);
  • 1
  • 2

NestedScrollView中嵌套RecyclerView出现的滑动冲突

  • 问题描述:
    RecyclerView滑动出现卡顿

  • 问题布局复原:

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/home_scroll_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

    </android.support.v4.widget.NestedScrollView>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 解决办法:
    在Activity或Fragment中, 为recyclerView设置如下代码:
recyclerView.setNestedScrollingEnabled(false);// 解决滑动冲突

猜你喜欢

转载自blog.csdn.net/qq_32320807/article/details/80625673