我的活动中有多个视图,包括2个垂直(1行)RecyclerViews.我禁用了RecyclerViews上的滚动,setNestedScrollingEnabled(false)只想让整个活动可滚动.这不符合预期.触摸RecyclerViews(我的AppBarLayout)外部的视图会触发滚动,但是当我尝试在其中一个内滚动时RecyclerViews,它就不再起作用了.我是否必须将触摸事件传递给我的主视图,还是有其他解决方案?
我的布局看起来像这样(剥离):
<android.support.design.widget.AppBarLayout>
<android.support.design.widget.CollapsingToolbarLayout>
<RelativeLayout>
<ImageView>
<LinearLayout>
<TextView />
<TextView />
</LinearLayout>
</RelativeLayout>
<android.support.v7.widget.Toolbar />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<Button />
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:scrollbars="none" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<Button />
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:scrollbars="none" />
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
编辑:刚刚添加了一张图片.触摸红色部分会按预期滚动整个活动,但触摸蓝色部分不会滚动任何内容.

小智 5
在NestedScrollView中使用RecyclerView
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false" />
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)
NestedScrollView为您的容器Button和RecyclerView布局。app:layout_behavior="@string/appbar_scrolling_view_behavior"为NestedScrollViewCoordinatorLayout作为根布局。试试这个结构:
<android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.AppBarLayout>
<android.support.design.widget.CollapsingToolbarLayout>
<RelativeLayout>
<ImageView>
<LinearLayout>
<TextView />
<TextView />
</LinearLayout>
</RelativeLayout>
<android.support.v7.widget.Toolbar />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<Button />
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:scrollbars="none" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<Button />
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:scrollbars="none" />
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
希望这会有所帮助~