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.
momo
source share