问题
I want to show and hide the action bar /toolbar as the Google Play store app. I am using sliding tabs on top and view pager to show the content of each tab. Here is the screenshot of Google play store app for the reference:
My layout XML :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<LinearLayout style="@style/HeaderBar"
android:id="@+id/headerbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="@layout/toolbar_no_bg"
android:id="@+id/toolbar_actionbar"/>
<com.fauzie.sample.tabsspinner.widget.SlidingTabLayout
android:background="@color/tab_background"
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/headerbar">
</android.support.v4.view.ViewPager>
</RelativeLayout>
Thanks in advance.
回答1:
Have a look at this:
https://github.com/flavienlaurent/NotBoringActionBar
There's a trick involved here. You'll need to:
- Wrap your layout in a list view
- Add a fake header with the same height as your action bar large header
- set your action bar overlay to true
- Translate the real header when the list moves (i.e. when the fake header is scrolled).
It's a little bit complicated at first but once you understand it, you see how smart and obvious it all is. The link will give you all you need I hope.
I myself used that link to implement it in my own app and it works great.
回答2:
Checkout this library: https://github.com/ksoichiro/Android-ObservableScrollView
this will definitely help you
回答3:
Check this example to implement this with the new official Android Design Support Library:
https://github.com/chrisbanes/cheesesquare
来源:https://stackoverflow.com/questions/26773245/show-and-hide-action-bar-while-scrolling-view-pager-content