Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make PagerTabStrip with two tabs equally fit in screen

I am using ViewPager with PagerTabStrip:

    <android.support.v4.view.ViewPager
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v4.view.PagerTabStrip
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="top"/>

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

And I would like to accomplish my tabs to look like this as Google recommends:

enter image description here

I have two tabs and I would like for each of them to be fixed and take 50% of the screen. I was looking through the options in XML and programmatically and can't find anything useful.

How can I accomplish that? Thank you.

like image 241
user4386126 Avatar asked Nov 25 '25 18:11

user4386126


2 Answers

I'm not sure about android.support.v4.view.PagerTabStrip. But you can use alternative library for getting this effect, i use it in my one project and it works well. After you add the lib to your project, set pstsShouldExpand to true

like image 184
dooplaye Avatar answered Nov 27 '25 07:11

dooplaye


You should use android.support.design.widget.TabLayout instead of PagerTabStrip.

like image 35
qianlv Avatar answered Nov 27 '25 06:11

qianlv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!