开发者

How can we specify width for each tab in tabhost?

开发者 https://www.devze.com 2023-03-01 04:06 出处:网络
I am using tabhost in my application. Can we give separate width property for each tab? i.e, one开发者_如何学JAVA with larger width and other with smaller?We can mention the tab width in code like:

I am using tabhost in my application. Can we give separate width property for each tab? i.e, one开发者_如何学JAVA with larger width and other with smaller?


We can mention the tab width in code like:

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


I tried below code and it worked perfectly fine for me

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

you can change width and height as per your need.


For your reference, if the parent layout of theTabWidget is LinearLayout, then you may need also to set the weight of the child LayoutParams. Since the tabs stretch its width in my case as its default weight is 1.0.

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

精彩评论

暂无评论...
验证码 换一张
取 消