Different tab sizes in Android

I have an application with 4 tabs. By default, each tab width is 1/4 of the width of the screen. How can I override this?

I need the tabs to have a different width for each. Any ideas on how to do this?

+6
android width android-tabhost tabs tabwidget
source share
3 answers

Try the following:

tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 35; 
+2
source share

Finally, I managed to use tabs of different sizes using ToggleButton.

My XML is like this

 <LinearLayout android:id="@+id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_below="@id/header" > <ToggleButton android:id="@+id/tab1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableRight="@drawable/icon_home" android:textOn="" android:textOff="" android:background="@drawable/tabselector" android:paddingLeft="15dip" android:paddingRight="15dip" android:layout_weight="0" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/top_menubar_separator" /> <ToggleButton android:id="@+id/tab2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableRight="@drawable/icon_store" android:textOn="Store" android:textOff="Store" android:background="@drawable/tabselector" android:paddingLeft="15dip" android:paddingRight="15dip" android:layout_weight="2" /> 

Where each ToggleButton is a tab. The trick here is to use weights to expand tabs to fill the screen completely.

Teab_selector.xml is as follows:

 <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/top_menubar_selected" android:state_pressed="true" /> <item android:drawable="@drawable/top_menubar_selected" android:state_checked="true" /> <item android:drawable="@drawable/top_menubar_1px" /> </selector> 

I still need to code the logic to release the button when a new one is selected and trigger the intent with ta, but so far it looks good.

+1
source share

Try the following:

 <TabWidget android:layout_width="wrap_content" ... /> 
0
source share

All Articles