• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Gravity driving me crazy

mjmarsh

Lurker
I've got a simple view with two TextViews inside a LinearLayout:

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

badgravity.bmp


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?
 
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:
<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
 
Back
Top Bottom