Gravity driving me crazy


Last Updated:

  1. mjmarsh

    mjmarsh New Member This Topic's Starter

    Joined:
    Jan 8, 2009
    Messages:
    2
    Likes Received:
    0
    I've got a simple view with two TextViews inside a LinearLayout:

    Code (Text):
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <LinearLayout
    3.     xmlns:android="http://schemas.android.com/apk/res/android"
    4.     android:layout_width="fill_parent"
    5.     android:layout_height="fill_parent"
    6.     android:orientation="horizontal"
    7.     android:background="#FFFFFF">
    8.     <TextView
    9.         android:layout_width="wrap_content"
    10.         android:layout_height="wrap_content"
    11.         android:text="Left"
    12.         android:textColor="#000000"
    13.         android:textSize="7pt"
    14.         android:layout_gravity="left" />
    15.     <TextView
    16.         android:layout_width="wrap_content"
    17.         android:layout_height="wrap_content"
    18.         android:text="Right"
    19.         android:textColor="#000000"
    20.         android:textSize="7pt"
    21.         android:layout_gravity="right" />
    22. </LinearLayout>
    see screenshot:

    I want something like:

    | Left <space here> Right|

    But I get

    | LeftRight <space here> |

    [​IMG]

    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?
     

    Advertisement
  2. mjmarsh

    mjmarsh New Member This Topic's Starter

    Joined:
    Jan 8, 2009
    Messages:
    2
    Likes Received:
    0
  3. Emmanuel

    Emmanuel New Member

    Joined:
    Jan 21, 2009
    Messages:
    2
    Likes Received:
    0
    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 !
     
  4. Phases

    Phases Community Manager Administrator

    Joined:
    Sep 9, 2008
    Messages:
    8,498
    Likes Received:
    18,872
    Gravity.. sheesh. ..Always tryin' to bring me down..
     
  5. Emmanuel

    Emmanuel New Member

    Joined:
    Jan 21, 2009
    Messages:
    2
    Likes Received:
    0
    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):
    1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    2.         android:orientation="horizontal"
    3.         android:layout_height="wrap_content"
    4.         android:layout_width="fill_parent">
    5.  
    6. <TextView xmlns:android="http://schemas.android.com/apk/res/android"
    7.         android:id="@+id/PlayerName"
    8.         android:textColor="#ffFFffFF"
    9.         android:layout_height="wrap_content"
    10.         android:layout_width="wrap_content"
    11.         android:layout_gravity="left"
    12.         android:text="Nom"
    13.         />
    14.  
    15. <TextView xmlns:android="http://schemas.android.com/apk/res/android"
    16.         android:id="@+id/PlayerScore"
    17.     android:layout_height="wrap_content"
    18.         android:layout_width="fill_parent"
    19.         android:gravity="right"
    20.         android:textColor="#ffFFffFF"
    21.         android:text="score"
    22.         />
    23.  
    24. </LinearLayout>
    I don't understand why a mere android:layout_gravity is not enough
     

Share This Page

Loading...