Issue with Gravity/Centering


Last Updated:

  1. Forest Marie

    Forest Marie Member This Topic's Starter

    Joined:
    Dec 29, 2009
    Messages:
    5
    Likes Received:
    0
    Below is the code...

    Code (Text):
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <RelativeLayout xmlns:android="[URL]http://schemas.android.com/apk/res/android[/URL]"
    4.     android:orientation="vertical"
    5.     android:layout_width="fill_parent"
    6.     android:layout_height="fill_parent"
    7.     android:background="#FFFFFF">
    8.    
    9.    
    10.     <TextView
    11.      android:layout_width="fill_parent"
    12.      android:id="@+id/tvJoke"
    13.      android:layout_height="wrap_content"
    14.      android:layout_marginTop="20dip"
    15.      android:layout_marginLeft="10dip"
    16.      android:textColor="#000000"
    17.     />
    18.    
    19.     <LinearLayout
    20.      android:layout_width="fill_parent"
    21.      android:layout_height="fill_parent"
    22.      [B]   android:gravity="bottom"
    23. [/B]     android:layout_below="@id/tvJoke">
    24.      
    25.   <Button
    26.    android:text="prev"
    27.    android:layout_height="wrap_content"
    28.    android:layout_width="100px"
    29.    android:id="@+id/btnPrevious">
    30.   </Button>
    31.   <Button
    32.    android:text="share"
    33.    android:id="@+id/btnMessage"
    34.    android:layout_width="100px"
    35.    android:layout_height="wrap_content">
    36.   </Button>
    37.   <Button
    38.    android:text="next"
    39.    android:layout_height="wrap_content"
    40.    android:layout_width="100px"
    41.    android:id="@+id/btnNext">
    42.   </Button>
    43. </LinearLayout>
    44. </RelativeLayout>
    45.  
    When I set the gravity in the Linear Layout to Bottom, the three buttons go to the bottom, but they are not horizontally centered. If I set the gravity to center_horizontal, the buttons are no longer aligned against the bottom of the screen - and they shouldn't be in this case...

    My question is what is the solution to horizontally center the buttons as well as aligning them toward the bottom?

    It would be nice if there was a gravity = "horizontal_center, bottom" -- two options

    Any help is much appreciated...
     

    Advertisement
  2. IanGClifton

    IanGClifton Well-Known Member

    Joined:
    Feb 7, 2010
    Messages:
    111
    Likes Received:
    19
    Have you tried android:gravity="bottom|center_horizontal"?
     
    Forest Marie likes this.
  3. Forest Marie

    Forest Marie Member This Topic's Starter

    Joined:
    Dec 29, 2009
    Messages:
    5
    Likes Received:
    0
    Ha, that worked. I didn't realize you can bit together the gravity enumerated values.

    THANK YOU Ian!
     

Share This Page

Loading...