Now you can Subscribe using RSS

Submit your Email

Friday

Android Scrollable Tabs like Play Store

Vishal Shrestha
This post shows how you can create Scrollable Tabs like Play Store in Android. The are a bunch of properties that you can apply to the tabs in tablayout.
Here is the most common example of Scrollable Tabs, the play store itself.

scrollabe tabs example used in play store

The tabLayout from Android Design Support Library provide properties using which you can create scrollable tabs. We will learn how to do so using XML and Programmatically too.
To create scrollable tabs in Android you simply need to set the tabMode property to scrollable.

<android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMode="scrollable"/> 


The design support library also provides other option of fixed, that can be used with tabGravity that can either be set to center or fill.


These properties with their result can be summed up from the image below.

Fixed tabs and Scrollable tabs like Play store
If you want to do these things programmatically instead of in XML, you can do the setTabMode function of tabLayout.
Example- 

 //For Scrollable Tabs
tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);

//For Fixed Tabs
tabLayout.setTabMode(TabLayout.MODE_FIXED);

//Setting Gravity to Center
tabLayout.setTabGravity(TabLayout.GRAVITY_CENTER);

//Setting Gravity to Fill
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);


Pretty easy, isn't it? Now Learn how to create nested tabs or Make your tabs scrollable like the play store or even better than that! If you have any questions, feel free to drop them below.

Vishal Shrestha / Author & Founder

A developer by profession, a born Adventurer. I mainly do Android but like to get my hands dirty with web development and a little bit of Python. I would't rather go on a Trek than a party and you can find me having a few rounds with the heavy bag to let out the steam ;)

For Business info : My Portfolio Site.

0 comments:

Post a Comment

Coprights @ 2017 | The Code City by Vishal Shrestha Vishal Shrestha