2010-12-16 51 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