Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 编辑文本标签?_Android_Android Edittext - Fatal编程技术网

Android 编辑文本标签?

Android 编辑文本标签?,android,android-edittext,Android,Android Edittext,我想有点像这样的布局 [text tabel][edittext] 我找不到类似html样式标签的属性。这似乎是我需要使用的情况 [TextView][EditText] 但是我不能让他们走在同一条线上这是我的xml文件 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_par

我想有点像这样的布局

[text tabel][edittext]
我找不到类似html样式标签的属性。这似乎是我需要使用的情况

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

您基本上有两种选择:

选项1:使用嵌套线性布局:
您的LinearLayout具有属性
android:orientation=“vertical”
,因此当然所有内容都将在其中垂直显示


尝试使用线性布局包装TextView和EditText,该布局具有
android:orientation=“horizontal”

设计支持库具有TextInputLayout,它可以在用户开始键入时将提示文本动画化为标签,还可以显示红色错误消息


文本输入布局
就是答案。 只需使用android材质库中的正确版本:

android:hint
参数将在文本区域显示标签,当您单击它时,标签将移动到文本字段上方

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


试试GridLayout。可能它太复杂了,但它保持基线,以便所有标签和编辑文本对齐。在标签视图上定义
android:labelFor
,以指示标签描述的项目。
<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>
<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>