How can we specify width for each tab in tabhost?

放肆的年华 提交于 2020-01-02 05:51:01

问题


I am using tabhost in my application. Can we give separate width property for each tab? i.e, one with larger width and other with smaller?


回答1:


We can mention the tab width in code like:

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



回答2:


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.




回答3:


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;


来源:https://stackoverflow.com/questions/5801825/how-can-we-specify-width-for-each-tab-in-tabhost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!