Я хотел бы спросить вас, как я могу поместить два EditText в одну строку?
Как поместить два EditText в одну строку
Ответ 1
Сделайте снимок:
<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>
Кроме того, вы должны попробовать принять ответы, если получите тот, который отвечает на ваш вопрос. Вероятнее всего, вы получите больше/лучших ответов.
Ответ 2
Существует несколько способов: 2.
С горизонтальным LinearLayout
Назначьте android:orientation="horizontal" внешнему LinearLayout. Таким образом, все дочерние элементы этого макета будут выровнены рядом друг с другом.
Пол-макет:
<LinearLayout android:orientation="horizontal">
<EditText />
<EditText />
</LinearLayout>
С RelativeLayout
Используйте android:layout_toLeftOf="@id/otheredittext" или android:layout_toRightOf="@id/..", чтобы сообщить одному из EditTexts, что он принадлежит правой/левой стороне другого, и выровнять первый по отношению к родительскому (RelativeLayout) с помощью android:layout_alignParentTop="true", то же самое с левым, правым или нижним.
Пол-макет:
<RelativeLayout>
<EditText android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:id="@+id/edittext1"
/>
<EditText android:layout_toRightOf="@id/edittext1" />
</RelativeLayout>
(Также обратите внимание, что при назначении идентификатора в первый раз в android:id у вас есть +id, и когда вы ссылаетесь на него с помощью макета через android:layout_to..., он просто id)
Ответ 3
Для линейного макета это будет следующим:
<?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>
Для относительной компоновки это будет следующим:
<?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>