android-viewpager – CoordinatorLayout与NestedScrollView和viewpager不兼容

前端之家收集整理的这篇文章主要介绍了android-viewpager – CoordinatorLayout与NestedScrollView和viewpager不兼容前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
最近,我使用 Android设计支持库,我的崩溃工具栏中有以下代码.
  1. <android.support.design.widget.CoordinatorLayout
  2. xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. android:layout_width="match_parent"
  5. android:layout_height="match_parent"
  6. >
  7.  
  8. <android.support.design.widget.AppBarLayout
  9. android:id="@+id/media_detail_appbar"
  10. android:layout_width="match_parent"
  11. android:layout_height="wrap_content"
  12. android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
  13. >
  14.  
  15. <android.support.design.widget.CollapsingToolbarLayout
  16. android:id="@+id/collapsing_toolbar"
  17. android:layout_width="match_parent"
  18. android:layout_height="match_parent"
  19. app:layout_scrollFlags="scroll|exitUntilCollapsed"
  20. app:contentScrim="?attr/colorPrimary"
  21. >
  22.  
  23. <include
  24. layout="@layout/layout_card"
  25. android:layout_width="match_parent"
  26. android:layout_height="match_parent"
  27. />
  28.  
  29. <android.support.v7.widget.Toolbar
  30. android:id="@+id/media_detail_toolbar"
  31. android:layout_width="match_parent"
  32. android:layout_height="?attr/actionBarSize"
  33. app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
  34. app:layout_collapseMode="pin"
  35. />
  36.  
  37. </android.support.design.widget.CollapsingToolbarLayout>
  38.  
  39. </android.support.design.widget.AppBarLayout>
  40.  
  41. <LinearLayout
  42. android:layout_width="match_parent"
  43. android:layout_height="match_parent"
  44. android:orientation="vertical"
  45. app:layout_behavior="@string/appbar_scrolling_view_behavior"
  46. >
  47.  
  48. <android.support.design.widget.TabLayout
  49. android:id="@+id/media_detail_tabs"
  50. android:layout_width="match_parent"
  51. android:layout_height="?android:attr/actionBarSize"
  52. android:background="@color/blue_2"
  53. app:tabMode="scrollable"
  54. />
  55.  
  56. <android.support.v4.view.ViewPager
  57. android:id="@+id/view_pager"
  58. android:layout_width="match_parent"
  59. android:layout_height="match_parent"
  60. />
  61.  
  62. </LinearLayout>
  63.  
  64. </android.support.design.widget.CoordinatorLayout>

View Pager有两个片段.一个是NestedScrollView,另一个是Recycler View.我的问题是NestedScrollView,这里是下面的代码.

  1. <android.support.v4.widget.NestedScrollView
  2. xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. >
  6. <LinearLayout
  7. android:layout_width="match_parent"
  8. android:layout_height="wrap_content"
  9. android:orientation="vertical"
  10. >
  11. </LinearLayout>
  12. </android.support.v4.widget.NestedScrollView>

我的问题是,当您向上滚动视图时,只要手指在侧面移动一点,它将触发视图寻呼机的水平滚动.请帮我避免吗?当我们上下滚动时,不应该触发视图寻呼机.它在我的回收商视图片段中运行良好.谢谢.

解决方法

我尝试使用最新版本的这些库的相同布局
  1. compile 'com.android.support:appcompat-v7:23.1.1'
  2. compile 'com.android.support:design:23.1.1'

它的工作原理如预期的那样:

如果手势主要是垂直滚动(甚至对角线),NestedScrollView触发滚动,否则如果手势主要是水平滑动(即使是最小的垂直间隙),ViewPager也会触发滑动.解决升级你的库.

猜你在找的Android相关文章