Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Right align column in android table layout

Tags:

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???

like image 816
Ankit HTech Avatar asked Oct 15 '12 05:10

Ankit HTech


People also ask

How do you right align text on android?

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.

Is table layout available in android?

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.

What is stretch column in android?

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.


1 Answers

Here you have to do

  1. set the table row width to fill_parent

  2. and set the android:layout_gravity="right" to the textview which you want to align right it to the table row

    ---- or ----

  1. add the weight to the textview inside a table row so that they can align how you want.
like image 130
Ram kiran Pachigolla Avatar answered Sep 20 '22 09:09

Ram kiran Pachigolla