EditText Label?
Chcę mieć jakiś layout trochę jak ten
[text tabel][edittext]
Nie mogę znaleźć atrybutu takiego jak etykieta html. Wygląda na to, że muszę użyć
[TextView][EditText]
Ale nie mogę ich zmusić do pójścia na tej samej linii to jest mój plik xml.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
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"/>
<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"/>
<Button android:id="@+id/close"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="@string/title_close" />
4 answers
Masz zasadniczo dwie opcje:
Opcja 1: Użyj zagnieżdżonych Liniowychlayouts:
<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" />
Zauważ, że używam android:orientation="horizontal"
dla tych zagnieżdżonych układów.
Opcja 2: możesz użyć innego menedżera zawartości, na przykład RelativeLayout
.
Zaletą tego jest to, że możesz uniknąć zagnieżdżania, dzięki czemu twój układ będzie łatwiejszy do odczytania/utrzymania / nadmuchania. To jest krótki przykład:
<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>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-07-22 18:26:48
Biblioteka wsparcia projektowania posiada TextInputLayout, który animuje tekst podpowiedzi zmieniając go w etykietę, gdy użytkownik zaczyna pisać, a także może wyświetlać czerwony komunikat o błędzie.
Https://developer.android.com/reference/android/support/design/widget/TextInputLayout.html
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-09-24 00:30:05
TextInputLayout
to jest odpowiedź.
Wystarczy użyć odpowiedniej wersji z biblioteki materiałów Androida:
https://developer.android.com/reference/com/google/android/material/textfield/TextInputLayout
Param android:hint
wyświetli etykietę w obszarze tekstowym, a po kliknięciu na nią etykieta zostanie przeniesiona nad pole tekstowe.
<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>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2020-09-27 11:07:27
Twój LinearLayout ma atrybut android:orientation="vertical"
więc oczywiście wszystko będzie wyświetlane w pionie.
Spróbuj zawijać TextView i EditText za pomocą LinearLayout, który ma android:orientation="horizontal"
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-09-18 13:31:50