How you can leave two parallel editText inside a ScrollView
in this image the editText comes out one under the other, I would like one to come out winged from the other since the numbers to enter are not more than 4 digits
defines the property android:orientation="horizontal"
to the container of both EditText
, in this way they would be shown both horizontally.
Regarding the EditText
, so that both elements have the same size you can add the property:
android:layout_weight="1"
Example:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:hint="Texto Izquierdo"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<EditText
android:hint="Texto derecho"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
</LinearLayout>
Something important to note is that when you use ScrollView
you must have only one container element (child element) which will be traversed by the ScrollView
.
To achieve what you need, simply add the following to your XML code.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:inputType="number"
android:hint="1234"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<EditText
android:inputType="number"
android:hint="1234"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
</LinearLayout>
<!--RESTO DE ELEMENTOS A AGREGAR-->
</LinearLayout>
</ScrollView>
With the value android:orientation="horizontal"
in LinearLayout
container will cause your EditText
to be distributed horizontally.
The values android:layout_weight="1"
in each EditText
are to achieve that your elements occupy each 50% of the total space on the screen.
The result would be the following: