2010-12-16 19 views
1

我想创建一个标签的用户界面,但我不想把任何图像放在tabHosts,所以而不是使用setIndicator(CharSequence标签,绘制图标)我决定使用setIndicator(CharSequence标签)。然后,tabHost创建时不包含图像,但不包含高度较小且仅包含CharSequence的图像,它与具有图像的常规tabHost具有相同的高度。图像通常位于顶部的空闲空间以及文本低于该空白空间。无论如何删除为图像保留的可用空间,或者翻转两个,以便文本在上面,之后我可以设置一个15dp的layout_height。主版面的.xml代码是Android:TabHost.TabSpec setIndicator(CharSequence标签)

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@android:id/tabhost" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <TabWidget 
     android:id="@android:id/tabs" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 
    <FrameLayout 
     android:id="@android:id/tabcontent" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:padding="5dp" /> 
</LinearLayout> 
</TabHost> 

回答

2

您可以将@null设置为背景,并将负边距设置为删除可用空间。

<TabWidget 
android:id="@android:id/tabs" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:background="@null" 
android:layout_marginLeft="-2dp" 
android:layout_marginRight="-2dp" /> 
+2

设置@null作为背景并没有帮助,而我只需要移除在TabWidget的上部空白处不能左右,但由于你的意见,我想通了,我可以只设置的android :layout_marginTop =“ - 25dp”,它解决了我的问题(我决定在顶部留下一些空间,以便用户在更改标签时不会发生困难) 谢谢您的建议! – Peter 2010-12-16 11:28:12