Question

this might have been asked before (and I apologise for that) but I couldn't find it so here I am.

I have a frame layout which is horizontally and vertically centered.There are two editText's in it, and I would like to arrange both of them to the center of the screen while maintaining a certain distance between the two of them.

I hope my drawing can give you an idea of what i want.

I have tried many things, but it seems it wasn't enought.Thanks for the help, and sorry for bothering!

http://oi59.tinypic.com/qxa2vm.jpg

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true" >

    <EditText
        android:id="@+id/editText_nume"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPersonName"
        android:text="@string/nume" />

    <EditText
        android:id="@+id/editText_parola"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        android:text="@string/parola" />
</FrameLayout>
Was it helpful?

Solution

Use LinearLayout instead of FrameLayout. FrameLayout is designed to block out an area on the screen to display a single item.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:orientation="vertical" >

        <EditText
            android:id="@+id/editText_nume"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPersonName"
            android:text="@string/nume" />

        <EditText
            android:id="@+id/editText_parola"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:inputType="textPassword"
            android:text="@string/parola" />

    </LinearLayout>

</RelativeLayout>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top