I've got a simple view with two TextViews inside a LinearLayout: Code (Text): <?xml version="1.0" encoding="UTF-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" android:background="#FFFFFF"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Left" android:textColor="#000000" android:textSize="7pt" android:layout_gravity="left" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Right" android:textColor="#000000" android:textSize="7pt" android:layout_gravity="right" /> </LinearLayout> see screenshot: I want something like: | Left <space here> Right| But I get | LeftRight <space here> | The upshot is I want the "Left" text on the left and the "Right" text on the right, but they both get bunched up on the left. I've tried the plain old "gravity" attribute and that does not work either. Any suggestions?
I found the answer. right and left gravity is not supported in a LinearLayout with Horizontal oritentation. Here is a work-around: http://groups.google.com/group/android-developers/browse_thread/thread/c67710fbc971a9d4/f3011cc8dd13216f?lnk=gst&q=LinearLayout+gravity#f3011cc8dd13216f
Thanks ! Your post gives me the solution for a problem I had for a long time ! I also tried to fight for hours with gravity in vain !
Hum... Actually, it doesn't work, textAlign is a deprecated parameter, and no longer exists ! I think there is a logical way with gravity and layout_gravity, but I didn't get it ! All I could do ( that still get the expected result ) was : Code (Text): <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_height="wrap_content" android:layout_width="fill_parent"> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/PlayerName" android:textColor="#ffFFffFF" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="left" android:text="Nom" /> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/PlayerScore" android:layout_height="wrap_content" android:layout_width="fill_parent" android:gravity="right" android:textColor="#ffFFffFF" android:text="score" /> </LinearLayout> I don't understand why a mere android:layout_gravity is not enough