Oreyne Lang
Oreyne Lang

Reputation: 107

How can I make this form on Android?

form

I have tried to make this small form in Android, but have not been able to make the space in the third and fourth rows.

Upvotes: 0

Views: 57

Answers (2)

khetanrajesh
khetanrajesh

Reputation: 300

Something like this :

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

<TextView
    android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Apellidos"/>

<EditText
    android:id="@+id/editText"
    android:layout_toRightOf="@+id/text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hind="Apellidos"/>


<LinearLayout
    android:layout_below="@+id/editText"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <RelativeLayout
        android:layout_weight="1"
        android:layout_marginRight="20dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/text2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:text="Ciudad"/>

        <EditText
            android:layout_toRightOf="@+id/text2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hind="Apellidos"/>

    </RelativeLayout>

    <RelativeLayout
        android:layout_marginLeft="20dp"
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/text3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:text="Ciudad"/>

        <EditText
            android:layout_toRightOf="@+id/text3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hind="Apellidos"/>

    </RelativeLayout>

</LinearLayout>

</RelativeLayout>

Edit :

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


<LinearLayout
    android:id="@+id/name"
    android:orientation="vertical"
    android:gravity="right"
    android:layout_width="wrap_content"
    android:layout_height="match_parent">
    <TextView
        android:id="@+id/text"
        android:padding="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Apellidos"/>

    <TextView
        android:id="@+id/text1"
        android:padding="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Apelli"/>

</LinearLayout>

<LinearLayout
    android:id="@+id/value"
    android:orientation="vertical"
    android:layout_toRightOf="@+id/name"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <EditText
        android:id="@+id/editText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/text"
        android:hind="Apellidos" />

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:layout_weight="2"
            android:layout_toRightOf="@+id/text2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:hind="Apellidos"/>

        <TextView
            android:layout_marginLeft="10dp"
            android:layout_weight="1"
            android:id="@+id/text2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="Ciudad"/>

        <EditText
            android:layout_weight="2"
            android:layout_toRightOf="@+id/text2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:hind="xyz"/>

    </LinearLayout>


</LinearLayout>

Upvotes: 0

Arpit
Arpit

Reputation: 2217

While you can implement this using a RelativeLayout, it is an ideal candidate for using ConstraintLayout which will let you specify element locations relative to each other and how they should expand/reposition themselves as the window resizes on tablets or in multiwindow mode.

Upvotes: 1

Related Questions