Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show and hide Action bar while scrolling view pager content

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:

enter image description hereenter image description here

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.

like image 926
mudit Avatar asked Nov 06 '14 06:11

mudit


3 Answers

Have a look at this:

https://github.com/flavienlaurent/NotBoringActionBar

There's a trick involved here. You'll need to:

  1. Wrap your layout in a list view
  2. Add a fake header with the same height as your action bar large header
  3. set your action bar overlay to true
  4. 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.

like image 166
kha Avatar answered Oct 17 '22 03:10

kha


Checkout this library: https://github.com/ksoichiro/Android-ObservableScrollView

this will definitely help you

like image 5
yshrsmz Avatar answered Oct 17 '22 04:10

yshrsmz


Check this example to implement this with the new official Android Design Support Library:

https://github.com/chrisbanes/cheesesquare

like image 3
Roel Avatar answered Oct 17 '22 03:10

Roel