Action Bar with fixed tabs menu

Asked

Viewed 447 times

0

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

How to get Pagertabstrip fixed as image?

The code I have for use is this

<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="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>

  • 1

    You can put the buttons on top and fragments which will alternate at the bottom. Search about fragments is interesting.

  • I’m wondering how to get the Pagertabstrip fixed as the image

1 answer

1

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

So I suggest using the library ViewPagerIndicator, made by Jake Wharton, who maintains the same behavior (equal to image) but with more customizations.

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

Using the 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>

Outside the ViewPager, other than PagerTabStrip.

And to configure the ViewPager with the 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 seen by the site Viewpagerindicator or by github.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.