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???
To right align text in TextView in Kotlin Android, set android:textAlignment attribute with the value “viewEnd” in layout file, or programmatically set the textAlignment property of the TextView object with View.
TableLayout is a ViewGroup that displays child View elements in rows and columns. Note: For better performance and tooling support, you should instead build your layout with ConstraintLayout. TableLayout positions its children into rows and columns.
Stretching ColumnsThe specified columns are stretched to take up any available space on the row. Examples: android:stretchColumns="1"—The second column (because the column numbers are 0-based) is stretched to take up any available space in the row.
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 ----
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With