Layouts and blank space


Last Updated:

  1. andywhoa

    andywhoa Well-Known Member This Topic's Starter

    Joined:
    May 15, 2010
    Messages:
    105
    Likes Received:
    13
    Suppose my layout is centered horizontally and vertically. Suppose I have 2 text views. Suppose I want a space between these text views so one isn't directly on top of the other. How would I do this? Is there a special tag? Do I need to use a TableLayout to space everything out good?
     

    Advertisement
  2. cp1

    cp1 Well-Known Member

    Joined:
    Apr 30, 2010
    Messages:
    375
    Likes Received:
    35
    You should be able to set the padding to get it how you like.
     
  3. andywhoa

    andywhoa Well-Known Member This Topic's Starter

    Joined:
    May 15, 2010
    Messages:
    105
    Likes Received:
    13
    Code (Text):
    1.  
    2. <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3.     android:orientation="vertical"
    4.     android:layout_width="fill_parent"
    5.     android:layout_height="fill_parent"
    6.     android:gravity="center_vertical|center_horizontal"
    7.     >
    8.     <TableRow
    9.         android:gravity="center">
    10.         <EditText
    11.             android:id="@+id/PasswordText"
    12.             android:password="true"
    13.             android:layout_height="wrap_content"
    14.             android:layout_width="250px"
    15.             android:layout_centerHorizontal="true"
    16.             android:layout_below="@+id/PasswordLabel"
    17.             android:singleLine="true"
    18.         />
    19.     </TableRow>
    20.     <TableRow
    21.         android:gravity="center">
    22.         <Button
    23.             android:id="@+id/LoginButton"
    24.             android:text="Log in"
    25.             android:layout_width="wrap_content"
    26.             android:layout_height="wrap_content"
    27.             android:layout_centerHorizontal="true"
    28.         />
    29.     </TableRow>
    30. </TableLayout>
    31.  
    Why is the LoginButton 250px wide? Shouldn't it be as wide as "Log in" takes to fit on the button? I was under the impression android:layout_width was relative to the button itself and not the are of the layout it is contained in.
     
  4. andywhoa

    andywhoa Well-Known Member This Topic's Starter

    Joined:
    May 15, 2010
    Messages:
    105
    Likes Received:
    13
    Ah, excellent. I'll use the padding properties to space appropriately. Thank you.


    My follow-up question still stands out of curiosity
     
  5. cp1

    cp1 Well-Known Member

    Joined:
    Apr 30, 2010
    Messages:
    375
    Likes Received:
    35
    I haven't used tables much, but in my experience it will make all the columns be the same width, so the button is the same width as the text above it.
     

Share This Page

Loading...