I want to draw a table in which last column should be at the right most side of the table.
This is how the table row looks like:
Admin (2)New
Network (2)New
And this is how it should be:
Admin (2) New
Network (2) New
XML:
<?xml version="1.0" encoding="utf-8"?>
<!-- row.xml -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="45dp"
android:gravity="center" android:background="@color/list_bg">
<TableLayout android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow>
<ImageView android:id="@+id/t1" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView android:id="@+id/t2" android:typeface="normal"
android:singleLine="true" android:textSize="14sp" android:textStyle="normal"
android:layout_width="wrap_content" android:textColor="#000000"
android:layout_height="wrap_content" />
<TextView android:id="@+id/t10" android:typeface="normal"
android:singleLine="true" android:text=" " android:textSize="14sp"
android:textStyle="normal" android:layout_width="wrap_content"
android:textColor="#000000" android:layout_height="wrap_content" />
<TextView android:id="@+id/t4" android:typeface="normal"
android:visibility="gone" android:singleLine="true" android:text="("
android:textSize="14sp" android:textStyle="normal"
android:layout_width="wrap_content" android:textColor="#000000"
android:layout_height="wrap_content" />
<TextView android:id="@+id/t5" android:typeface="normal"
android:visibility="gone" android:singleLine="true"
android:textSize="14sp" android:textStyle="normal"
android:layout_width="wrap_content" android:textColor="#000000"
android:layout_height="wrap_content" />
<TextView android:id="@+id/t6" android:typeface="normal"
android:visibility="gone" android:singleLine="true" android:text=")"
android:textSize="14sp" android:textStyle="normal"
android:layout_width="wrap_content" android:textColor="#000000"
android:layout_height="wrap_content" />
<ImageView android:id="@+id/t3" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView android:id="@+id/t7" android:typeface="normal"
android:visibility="visible" android:singleLine="true" android:text="New"
android:textSize="14sp"
android:textStyle="normal" android:layout_width="wrap_content"
android:textColor="#000000" android:layout_height="wrap_content" />
</TableRow>
</TableLayout>
</RelativeLayout>
In this xml t7 should be right at right most side of the table, how to do this???
Ram kiran
Here you have to do
set the table row width to
fill_parent
and set the
android:layout_gravity="right"
to the textview which you want to align right it to the table row---- or ----
- add the weight to the textview inside a table row so that they can align how you want.
- android:stretchColumns="x" where x is the column you want to fill
- android:layout_width="fill_parent" to ensure everything fills the screen
- android:layout_gravity="right" for the view component in column "x"
example (pseudo code):
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1">
<TableRow>
<TextView android:text="Left Column" />
<TextView android:layout_gravity="right|center_vertical" android:text="Right Adjusted Column" />
</TableRow>
</TableLayout>
来源:https://stackoverflow.com/questions/12889979/right-align-column-in-android-table-layout