Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Right aligning text in android?

Is there anything special I need to do to get text right aligned in a <TableLayout>?

The following simple example seems to align the text right-edged on the center of the screen, almost as if layout_span had no effect.

<TableLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        >
    <TableRow>
        <TextView
                android:text="Some text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:layout_span="2"
                />
    </TableRow>
    <TableRow>
        <Button
                android:text="Button 1"
                android:layout_weight="50"/>
        <Button
                android:text="Button 2"
                android:layout_weight="50"/>
    </TableRow>
</TableLayout>
like image 397
Stefan Kendall Avatar asked Apr 19 '11 02:04

Stefan Kendall


1 Answers

Fixed.

Removed Portion from TextView :

android:layout_gravity="right"
android:layout_span="2"

Updated Portion in TextView:

android:gravity="right"
android:layout_weight="1.0"


 <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_height="fill_parent"
      android:layout_width="fill_parent" >

      <TableRow>
           <TextView
                 android:text="Some text"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:gravity="right"
                 android:layout_weight="1.0" />
      </TableRow>
      <TableRow>
            <Button
                 android:text="Button 1"
                 android:layout_weight="50"/>
            <Button
                 android:text="Button 2"
                 android:layout_weight="50"/>
       </TableRow>
 </TableLayout>
like image 163
Kartik Domadiya Avatar answered Sep 18 '22 17:09

Kartik Domadiya