How do I get rid of spacing between tabs in Android application?
I have 4 tabs that I load using a TabHost and TabWidget using the following layout:
<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>
This looks great in my emulator and also great on my friends G2, however on my EVO 4G there is weird spacing between each tab. It looks like 5 or so pixels between each of the 4 tabs I load.
Again, in an emulator that has the exact same resolution of the EVO (800x480) it looks fine, no spacing between tabs. Why does it look different on my EVO? I've tried everything I can think of to get rid of the spacing, and nothing works.you can set background color for tabwidget. see following function for example.
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"));
}}
精彩评论