TAB Layout Width

回眸只為那壹抹淺笑 提交于 2019-12-22 01:36:07

问题


I am stuck in my xml code

<TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" />

I am trying to change the width to a custom set dip number but

android:layout_width="50dip"

is not making any affect to the tab width layout any suggenstion on this one please ?

Here is the full XML file Layout on pasteBin

http://pastebin.com/7vi4Pi8Z

Thanks Shiraz


回答1:


No body contributed the answer but after few hours of struggle i have found the way to set the width of tabs in java code... here you go, if some one may need this later

TabWidget tabWidget = (TabWidget) findViewById(android.R.id.tabs);
final int tabChildrenCount = tabWidget.getChildCount();
for (int i=0; i< tabChildrenCount; i++)
{
        // change the value 110 to whatever suits you for tab width
    tHost.getTabWidget().getChildAt(i).getLayoutParams().width = 110;
}

many thanks shiraz




回答2:


If you don't need each tab different size, then simplest width reduction may be adding something like

android:weightSum="5"

to your TabWidget parameters.



来源:https://stackoverflow.com/questions/6428602/tab-layout-width

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