【发布时间】:2015-09-15 17:15:37
【问题描述】:
我有一个AppBarLayout,它的子级中包含一个水平的RecyclerView。
AppBarLayout 的兄弟是ViewPager(其中包含一个垂直的RecyclerView)。
这是 XML:
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinatorLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.search.SearchResultFragment">
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="@dimen/d2"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<LinearLayout
android:id="@+id/header_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@color/white"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/back_image_view"
android:layout_width="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:scaleType="center"
android:src="@drawable/ic_backarrow_gray"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/query_terms_recycler_view"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="1"/>
<ImageView
android:id="@+id/search_image_view"
android:layout_width="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:scaleType="center"
android:src="@drawable/ic_search_gray"/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/related_terms_recycler_view"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/search_term_bg"
app:layout_scrollFlags="scroll|enterAlways"/>
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="@dimen/d8"
android:background="@color/tab_and_nav_bar"/>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
我已经有了另一个带有 AppBarLayout 的 UI,它能够使用 Toolbar 成功响应滚动。代码几乎相同,但在这种情况下出现了问题,因为 RecyclerView 没有折叠/隐藏。
【问题讨论】:
-
您的具体问题是什么?
-
它只是不响应滚动手势。它应该隐藏回收站视图,但没有任何反应。
-
我相信“可滚动”(可隐藏)视图必须位于顶部。如果您将 RecyclerView 在 LinearLayout 之前移动,它会起作用吗?
-
我的意思是AppBarLayout的内容应该是 1. RecyclerView (with scrollFlags); 2 线性布局; 3.标签布局。是这样的吗?
-
嘿,我正在尝试。我会在下面回复你的回答。
标签: android android-support-library android-design-library android-appbarlayout