I use tablelayout instead of the custom header title bar
Now my layout like the xml I show below, and I want to put the 2 icon and the text align right, but when I use android:layout_gravity="right" it seems not work, so how can I do it ?
This is my layout xml:
< ? xml version="1.0" encoding="utf-8"?>
< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="#4494D1" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right" >
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="简易尺子"
android:textColor="#fff"
android:textSize="25dp"
android:layout_marginTop="5dp"
android:layout_marginLeft="15dp"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="28dp"
android:layout_height="28dp"
android:background="@drawable/android2"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="5dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="关于"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:orientation="vertical" >
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="28dp"
android:layout_height="28dp"
android:background="@drawable/programs"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="帮助"
android:textColor="#fff" />
</LinearLayout>
</TableRow>
</TableLayout>
<SurfaceView
android:layout_width="match_parent"
android:id="@+id/surfaceView1"
android:layout_height="match_parent">
</SurfaceView>
</LinearLayout>
The layout gravity you set is not to affect the positioning of the
TextViewand theImageViewin the TableRow, rather it will position them in the wrappingLinearLayoutwhich is not quite what you need. I suggest you define the following attribute to yourTableLayout:This will make the first two columns of the raw expand and thus shrink the rightmost column to the right.
NOTE (IMPORTANT) Currently you do not have a valid layout defined: you have a
TableRowinLinearLayout– this is not allowed – you should place the row inTableLayoutlike the one I have defined.