Action Bar with fixed tab menu

0

I have a question about creating a fixed navigation menu like this

HowdoIgetthePagerTabStripfixedfromtheimage?

ThecodeIhavetouseisthis

<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">


    <android.support.v4.view.PagerTabStrip
        android:id="@+id/pager_title_strip"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:background="#33b5e5"
        android:textColor="#fff"
        android:paddingTop="4dp"
        android:paddingBottom="4dp"/>

</android.support.v4.view.ViewPager>

    
asked by anonymous 21.05.2014 / 20:52

1 answer

1

If using PagerTitleStrip and PagerTabStrip do not answer because they move as navigation occurs.

I suggest using Jake Wharton's ViewPagerIndicator library that maintains the same behavior (same as the image) but with more customizations.

There is also another library that does the same thing, but has a sliding effect on the flip indicator. It would be the case PagerSlidingTabStrip , made by Andreas Stütz, but the essence is the same.

Using ViewPagerIndicator would be something like:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <com.viewpagerindicator.TitlePageIndicator
        android:id="@+id/titles"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:layout_gravity="top"
        android:background="#33b5e5"
        android:textColor="#fff"
        android:paddingTop="4dp"
        android:paddingBottom="4dp" />
</RelativeLayout>

Out of ViewPager , other than PagerTabStrip .

And to set ViewPager to TitlePageIndicator would be something like:

//Set the pager with an adapter
ViewPager pager = (ViewPager)findViewById(R.id.pager);
pager.setAdapter(new TestAdapter(getSupportFragmentManager()));

//Bind the title indicator to the adapter
TitlePageIndicator titleIndicator = (TitlePageIndicator) findViewById(R.id.titles);
titleIndicator.setViewPager(pager);

Just as it is in the documentation that can be viewed by ViewPagerIndicator or by github .

    
21.05.2014 / 23:54