android - Display a Viewpager that scrolls together with a RecyclerView -
i want display viewpager scrolls when recyclerview have placed below scrolls up.
the information displayed in recyclerview depends on page displayed in viewpager. above viewpager there toolbar.
this layout i'm using:
<?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>
note: multiviewpager viewpager displays part of previous , next pages.
when page selected, replace framelayout fragment contains recyclerview. layout of fragment following:
<?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 seems work in kitkat, when try on marshmallow behaviour strange: scroll moves viewpager in different way recyclerview.
note 2: in kitkat have force scroll reset position when app starts, because scroll displaced top. code use resetting is:
scrollview.post(new runnable() { public void run() { scrollview.fullscroll(view.focus_up); } });
any other layout suggestion or idea how implement layout appreciated.
try nestedscrollview instead of scrollview. being said, don't need if inside of scrolling view use recyclerview. can assign behaviour of app bar scroll recyclerview directly , manage scrolling , collapsing of appbar. note, if use nestedscrollview, need set fill view port better performance , look.
Comments
Post a Comment