Question

I'm trying to group 3 objects in one view, and then center that view in the parent. My current results ( freeimagehosting.net/ktxbp ) shows the username bar centered both ways, and then the password and login objects below it. From the picture, you can see my problem. I'm trying to make equal distance from the username bar to the top and the login button to the bottom. How would I do this? here is my code:

 <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" 
android:background="@drawable/login"
 > 

<EditText
    android:layout_width="150dp"
    android:layout_height="wrap_content"
    android:background="@drawable/loginbutton"
    android:layout_centerInParent="true"
    android:text="Username"
    android:textSize="25dp"
    android:gravity="center_horizontal|center_vertical"
    android:textColor="#000000"
    android:layout_margin="10dp"
    android:id="@+id/username">




</EditText>

    <EditText
    android:layout_width="150dp"
    android:layout_height="wrap_content"
    android:background="@drawable/loginbutton"
    android:layout_below="@id/username"
    android:layout_centerInParent="true"
    android:text="Username"
    android:textSize="25dp"
    android:password="true"
    android:gravity="center_horizontal|center_vertical"
    android:textColor="#000000"
    android:layout_margin="10dp"
    android:id="@+id/password">
</EditText>

    <Button
    android:layout_width="125dp"
    android:layout_height="wrap_content"
    android:background="@drawable/loginbutton"
    android:layout_below="@id/password"
    android:layout_centerInParent="true"
    android:text="Login!"
    android:textSize="35dp"
    android:gravity="center_horizontal|center_vertical"
    android:textColor="#000000"
    android:layout_margin="10dp"
    android:id="@+id/loginbutton">
    </Button>

Was it helpful?

Solution

You should put the EditTexts and the Button in a RelativeLayout, and center it with android:layout_centerInParent="true".

(btw you didn't closed the RelativeLayout in the end)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top