How can we specify the width for each tab in tabhost?

I am using tabhost in my application. Can we provide a separate width property for each tab? that is, one with a larger width and the other with a smaller one?

+4
source share
3 answers

We can specify the tab width in the code, for example:

tabHost.getTabWidget().getChildAt(0).getLayoutParams().width = 50; 
+11
source

I tried under the code and worked perfectly for me

 LayoutParams params = tabHost.getTabWidget().getChildAt(0).getLayoutParams(); params.width = 170; params.height = 120; tabHost.getTabWidget().getChildAt(0).setLayoutParams(params ); 

You can change the width and height to suit your needs.

+4
source

For your reference, if the TabWidget's parent layout is LinearLayout, you may also need to set the weight of the LayoutParams child layout. Since tabs stretch their width in my case, since its default weight is 1.0.

 ((LinearLayout.LayoutParams)mTabHost.getTabWidget().getChildAt(i).getLayoutParams()).weight = 0; 
+3
source

All Articles