How to put two EditText in the same line
Give this a shot:
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"/> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"/></LinearLayout>
Also, you should try accepting answers if you get one that answers your question. You'll be more likely to get more/better responses.
There are multiple ways, here are 2.
With a horizontal LinearLayout
Assign android:orientation="horizontal"
to your outer LinearLayout
. This way all child elements of this layout will be aligned next to each other.
Semi-layout:
<LinearLayout android:orientation="horizontal"> <EditText /> <EditText /></LinearLayout>
With a RelativeLayout
Use android:layout_toLeftOf="@id/otheredittext"
or android:layout_toRightOf="@id/.."
to tell one of the EditTexts that it belongs to the right/left of the other one and align the first one relative to the parent (the RelativeLayout
) by using android:layout_alignParentTop="true"
, same with left, right or bottom.
Semi-layout:
<RelativeLayout> <EditText android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:id="@+id/edittext1" /> <EditText android:layout_toRightOf="@id/edittext1" /></RelativeLayout>
(Also notice that you have a +id
when assigning the id for the first time in android:id
and when you reference it from the layout via android:layout_to...
, it's just id
)
For Linear layout it will be as follows:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal"><EditText android:id="@+id/editText1" android:layout_height="wrap_content" android:layout_width="100dip"> <requestFocus></requestFocus></EditText><EditText android:layout_height="wrap_content" android:id="@+id/editText2" android:layout_width="100dip"></EditText></LinearLayout>
For relative layout it will be as follows:
<?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" ><EditText android:id="@+id/editText1" android:layout_height="wrap_content" android:layout_width="100dip"> <requestFocus></requestFocus></EditText><EditText android:layout_height="wrap_content" android:layout_width="100dip" android:id="@+id/editText2" android:layout_alignParentTop="true" android:layout_centerHorizontal="true"></EditText></RelativeLayout>