Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create layout in relative layout

Tags:

android

layout

I need to create the layout like this but not getting perfect.

getting this

enter image description here

need this way

enter image description here

I am creating this using RelativeLayout and need to create in this only. I am able to create with sub layout using Linearlayout but can this possible without using any sub layout

this is my code

<RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="15dp">
      <TextView android:text="Title" android:textColor="#ffffff" android:layout_width="wrap_content"
          android:layout_height="wrap_content" android:textSize="18dp" android:padding="5dp"
          android:background="@drawable/tab_cyan" android:id="@+id/title_add_txt"/>
      <EditText android:hint="Address Title" android:layout_width="match_parent" android:layout_height="wrap_content"
           android:id="@+id/address_title" android:layout_toRightOf="@id/title_add_txt"/>
       <TextView android:text="Address" android:textColor="#ffffffff" android:layout_width="wrap_content"
           android:layout_height="wrap_content" android:textSize="18dp" android:padding="5dp"
           android:background="@drawable/tab_cyan" android:layout_below="@id/title_add_txt"
           android:id="@+id/address_txt"/>
       <EditText android:hint="Address" android:layout_width="match_parent" android:layout_height="wrap_content"
           android:id="@+id/address" android:layout_below="@id/address_title" android:layout_toRightOf="@id/address_txt"/>
</RelativeLayout>
like image 905
Pratik Avatar asked Mar 15 '26 02:03

Pratik


2 Answers

I'm not able to test it, but see if this might help:

<RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="15dp">
    <TextView android:text="Title" android:textColor="#ffffff" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:textSize="18dp" android:padding="5dp"
        android:background="@drawable/tab_cyan" android:id="@+id/title_add_txt"/>
    <EditText android:hint="Address Title" android:layout_width="match_parent" android:layout_height="wrap_content"
        android:id="@+id/address_title" android:layout_toRightOf="@id/title_add_txt"/>
    <TextView android:text="Address" android:textColor="#ffffffff" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:textSize="18dp" android:padding="5dp"
        android:background="@drawable/tab_cyan" android:layout_below="@id/address_title"
        android:id="@+id/address_txt"/>
    <EditText android:hint="Address" android:layout_width="match_parent" android:layout_height="wrap_content"
        android:id="@+id/address" android:layout_alignTop="@id/address_txt" android:layout_alignLeft="@id/address_title"/>
</RelativeLayout>

What I've done is as follows: align address_txt below address_title (instead of below title_add_txt). I've also changed the alignment of address to align to the top of address_txt and to the left of address_title (this might probably be solved in other ways too).

Ad I said: I'm not able to verify it, but you can give it a try at least.

like image 62
Julian Avatar answered Mar 17 '26 15:03

Julian


It seems your TextView and EditText aren't the same size. If you could make them the same size, they would probably align fine.

Providing the size of your views, yourbest bet is probably to stick with your sub LinearLayouts.

like image 44
jcxavier Avatar answered Mar 17 '26 15:03

jcxavier



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!