So, if you want to do this, you will need to do some dirty things. Since fill_parent does not work, you need to make the root view have more height than the height of the tab, and then center what you really need. So my first LinearLayout is useless, and the second will be in the center of the tab.
Here is what I used. I just lose one text image with another in the upper right corner.
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:visibility="invisible"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:orientation="vertical"> <TextView android:id="@+id/tv_tab_count" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/tv_tab_title" android:layout_gravity="right" android:background="@drawable/bg_notification" android:paddingLeft="2dp" android:paddingRight="2dp" android:text="1" android:gravity="center" android:minWidth="14dp" android:textStyle="bold" android:textColor="@color/blanc" android:textSize="8dp" /> <TextView android:id="@+id/tv_tab_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" android:textColor="@color/noire" android:textSize="12dp" android:textStyle="bold" /> <TextView //this has the same height as the `tv_tab_count` so it remains centered vertically android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/tv_tab_title" android:layout_gravity="right" android:background="#0f0" android:paddingLeft="2dp" android:paddingRight="2dp" android:text="1" android:textSize="8dp" android:visibility="invisible" /> </LinearLayout>
This work for vertical alignment, but the view only has the width of the content that I put in the text image. Therefore, if you need to use full width, you must put a really very long word in one of the invisible text views.
Stephane mathis
source share