I want to have some layout a bit like this
[text tabel][edittext]
i cant find an attribute like html esque label. It seems to be the case t
TextInputLayout
is the answer.
Just use the correct version from the android material library:
https://developer.android.com/reference/com/google/android/material/textfield/TextInputLayout
The android:hint
param will display the label in the text area, and when you click on it label will be moved above the text field.
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/points">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:id="@+id/points_gs_input"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
The design support library has the TextInputLayout which animates the hint text turning it into a label when the user starts typing and can also show a red error message.
https://developer.android.com/reference/android/support/design/widget/TextInputLayout.html
Your LinearLayout has the attribute android:orientation="vertical"
so of course everything is going to be displayed vertically within it.
Try wrapping a TextView and EditText with a LinearLayout that has android:orientation="horizontal"
You have basically two options:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/boat_1"/>
<EditText
android:id="@+id/entry"
android:hint="@string/IRC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/boat_2"/>
<EditText
android:id="@+id/entry"
android:hint="@string/IRC"
android:minWidth="100dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"/>
</LinearLayout>
<Button android:id="@+id/close"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="@string/title_close" />
Notice that I'm using android:orientation="horizontal"
for those nested layouts.
RelativeLayout
.The advantage of this, is that you can avoid nesting, thus your layout will be easier to read/maintain/inflate. This is a brief example:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/text_view_boat1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/boat_1"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"/>
<EditText
android:id="@+id/entry"
android:hint="@string/IRC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:layout_toRightOf="@+id/text_view_boat1"
android:layout_alignParentTop="true"/>
<TextView
android:id="@+id/text_view_boat2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/boat_2"
android:layout_alignParentLeft="true"
android:layout_below="@id/text_view_boat1"/>
<EditText
android:id="@+id/entry2"
android:hint="@string/IRC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:layout_toRightOf="@+id/text_view_boat2"
android:layout_below="@id/entry"/>
</RelativeLayout>