如何消除Android应用程序中选项卡之间的间距?

时间:2011-02-25 06:38:37

标签: android android-layout

我使用以下布局使用TabHost和TabWidget加载了4个选项卡:

<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" 
    android:padding="0dp"
    android:layout_margin="0dp">
    <LinearLayout android:orientation="vertical"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:background="#FFFFFF" 
        android:padding="0dp"
        android:layout_margin="0dp">
        <ImageView android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:src="@drawable/titlebar" />
        <LinearLayout android:orientation="horizontal"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:background="#AAAAAA" 
            android:padding="0dp"
            android:layout_margin="0dp">
            <TabWidget android:id="@android:id/tabs"
                android:tabStripEnabled="true" 
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" />
        </LinearLayout>
        <FrameLayout android:id="@android:id/tabcontent"
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent"
            android:padding="0dp" 
            android:layout_margin="-5dp" />
    </LinearLayout>
</TabHost> 

这在我的模拟器中看起来很棒,而且对我的朋友G2来说也很棒,但是在我的EVO 4G上,每个标签之间都有奇怪的间距。它看起来像我加载的4个标签之间的5个左右的像素 同样,在具有与EVO(800x480)完全相同分辨率的仿真器中,它看起来很好,标签之间没有间距。
为什么我的EVO看起来有所不同?
我已经尝试了所有我能想到的东西来摆脱间距,没有任何作用。

1 个答案:

答案 0 :(得分:0)

您可以为tabwidget设置背景颜色。例如,参见以下功能。

    public static void setTabColor(TabHost tabhost) { 
        for(int i=0;i<tabhost.getTabWidget().getChildCount();i++){ 
     tabhost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#ff383737")); //unselected 
    } 
    tabhost.getCurrentTabView().setBackgroundColor(Color.parseColor("#ffe9e8e8"));
}}