views:

66

answers:

2

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

I need the tabs to have a different width for each one. Any ideas on how to accomplish that?

A: 

Try this:

<TabWidget android:layout_width="wrap_content" ... />
radek-k
Hi radek-k, I'm already using "wrap_content" and makes no difference if I change it. Probably is due I'm using a View as Tab Indicator, not just text. Thanks anyway
momo
A: 

Finally I managed to have a different sized tabs 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 using the weight to expand the tabs to completely fill the screen.

The teab_selector.xml looks like this

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;
    <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 for un-press a button when a new one is selected and launch an intent with ta activity, but looks nice so far.

momo