Я хочу отобразить Viewpager, который прокручивается, когда RecyclerView, который я разместил ниже, прокручивается вверх.Отобразите Viewpager, который прокручивается вместе с RecyclerView
Информация, отображаемая в RecyclerView, зависит от страницы, отображаемой в представлении. Над Viewpager находится панель инструментов.
Это макет, я использую:
<?xml version="1.0" encoding="utf-8"?>
<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=".main.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/toolbarTitle"
android:layout_width="wrap_content"
android:layout_height="?attr/actionBarSize"
android:gravity="center_vertical"
android:textColor="@color/text_white"
android:textSize="18sp"
android:textStyle="bold"/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.pixplicity.multiviewpager.MultiViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="220dp"
android:background="@color/black"
app:matchChildWidth="@+id/page"/>
<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>
</android.support.design.widget.CoordinatorLayout>
Примечание: MultiViewPager является ViewPager, который отображает часть предыдущих и последующих страницах.
Когда выбрана страница, я заменяю рамную рамку фрагментом, содержащим RecyclerView. Схема фрагмента выглядит следующим образом:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<TextView
android:id="@+id/emptyView"
style="@style/no_data"
android:text="@string/movements_no_data"
android:visibility="gone"/>
</FrameLayout>
Althought, кажется, работает в KitKat, когда я пытаюсь его на Зефир поведение странно: свиток перемещает ViewPager по-другому, что RecyclerView.
Примечание 2: в Kitkat мне нужно заставить свиток сбросить свое положение, когда приложение запустится, потому что свиток сначала смещается из TOP. Код я использую для обнуления является:
scrollView.post(new Runnable() {
public void run() {
scrollView.fullScroll(View.FOCUS_UP);
}
});
Любое другое расположение предложения или идеи о том, как реализовать эту схему будут оценены.
Добавить требуемый макет в качестве заголовка в ваш recyclerView –
Отредактировано в соответствии с предложением. – Fer