У меня есть ViewPager с фрагментами, которые содержат RecyclerViews. CollapsingTollbarLayout находится над ViewPager. Все работает нормально, за исключением программной прокрутки RecyclerView. Тогда AppBarLayout или CollapsingToolbarLayout не отвечают.
Вот мой базовый макет xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="256dp"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_behavior="de.wackernagel.playball.ui.FlingBehaviour">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:id="@+id/collapsingToolbarLayout"
app:contentScrim="?attr/colorPrimary"
app:titleEnabled="false"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:contentDescription="@null"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/showdown"
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/doubleActionBarSize"
android:minHeight="?attr/actionBarSize"
android:gravity="top"
app:titleMarginTop="14dp"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@android:color/transparent"
android:layout_gravity="bottom"
app:tabTextColor="#BEFFFFFF"
app:tabSelectedTextColor="#FFFFFFFF"
app:tabContentStart="@dimen/keyline_2"
app:tabMode="scrollable" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
My goal is it to collapse the CollapsingToolbarLayout during a programmatically scroll like a normal touch scroll.
я делаю это по
Activity get Fragment at current viewpager position
Fragment get LayoutManager from RecyclerView
LayoutManager scrollToPosition x
Поведение прокрутки работает в RecyclerView, но CollapsingToolbarLayout не отвечает.
ИЗМЕНИТЬ
Вот расположение моих фрагментов:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<de.wackernagel.playball.views.EmptyAwareRecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="8dp" />
<TextView
android:id="@android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"/>
isInTouchMode
возвращает true, если последнее взаимодействие с пользователем было с помощью касания, а не клавиатуры, dpad, пульта дистанционного управления и т. д. - person ataulm   schedule 16.10.2015