Подтвердить что ты не робот

Ярлык EditText?

Я хочу, чтобы некоторый макет немного похож на этот

[text tabel][edittext]

Я не могу найти такой атрибут, как html esque label. Кажется, что мне нужно использовать

[TextView][EditText]

но я не могу заставить их идти по одной строке, это мой 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" />

4b9b3361

Ответ 1

У вас есть в основном два варианта:

Вариант 1: использование вложенных LinearLayouts:

<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" /> 

Обратите внимание, что я использую android:orientation="horizontal" для этих вложенных макетов.

Вариант 2: вы можете использовать другой менеджер контента, например RelativeLayout.

Преимущество этого заключается в том, что вы можете избежать вложенности, поэтому ваш макет будет легче читать/поддерживать/раздувать. Это краткий пример:

<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>

Ответ 2

Библиотека поддержки дизайна имеет TextInputLayout, которая анимирует текст подсказки, превращая ее в метку, когда пользователь начинает вводить текст, а также может показывать красное сообщение об ошибке.

https://developer.android.com/reference/android/support/design/widget/TextInputLayout.html

Ответ 3

У вашего LinearLayout есть атрибут android:orientation="vertical", поэтому, конечно, все будет отображаться вертикально внутри него.

Попробуйте обернуть TextView и EditText с помощью LinearLayout с android:orientation="horizontal"