简体   繁体   English

如何在TabHost中更改选项卡小部件的大小

[英]how to change the tab widget size in TabHost

In my application i use the tabhost in linear layout, tabhost contains 4 tabs. 在我的应用程序中,我以线性布局使用tabhost,tabhost包含4个标签。 The size of the tabwidget is very very high and it shows title very small. 该选项卡的大小非常大,并且显示的标题非常小。 Can any one help me how to reduce the size of tabwidget. 谁能帮我减少Tabwidget的大小?

I would insist to create custom Tabs using setIndicator(View) . 我会坚持使用setIndicator(View)创建custom Tabs So, create a TextView of your desired size and set it to the TabWidget. 因此,创建所需大小的TextView并将其设置为TabWidget。 Here is an Tutorial for the same with Example. Here是与Example相同的教程。

You can just inflate a TextView and set it to the TabWidget using 您可以使用以下方法为TextView充气并将其设置为TabWidget

View view = LayoutInflater.from(context).inflate(R.layout.your_custom_tab-layout,
                                                                           null);
TextView tv = (TextView) view.findViewById(R.id.my_text_view);
TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tv).
                                                              setContent(intent);
mTabHost.addTab(setContent);

I'm not clear on exactly what you're looking to do here, but I'll make a guess at it. 我不清楚您要在这里做什么,但我会做一个猜测。

If you don't want space to be taken up by graphics (in other words, have text only) you can set the height and graviy of the widget to effectively remove the space that is used by the graphic, making for a much more compact tab label (vertically). 如果您不希望图形占用空间(换句话说,仅包含文本),则可以设置窗口小部件的高度和重力,以有效删除图形使用的空间,从而使图形更紧凑标签标签(垂直)。

    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="30dp"
        android:gravity="bottom" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM