首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >EditText标签?

EditText标签?
EN

Stack Overflow用户
提问于 2010-09-18 21:28:43
回答 4查看 78K关注 0票数 27

我想要一些像这样的布局

代码语言:javascript
复制
[text tabel][edittext]

我找不到像html esque标签这样的属性。这似乎是我需要使用的情况

代码语言:javascript
复制
[TextView][EditText]

但是我不能让它们在同一行上,这是我的xml文件。

代码语言:javascript
复制
<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" />

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2010-09-18 21:31:35

你基本上有两个选择:

选项1:使用嵌套LinearLayouts:

代码语言:javascript
复制
<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

这样做的好处是,您可以避免嵌套,因此您的布局将更容易阅读/维护/膨胀。这是一个简单的示例:

代码语言:javascript
复制
<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>
票数 32
EN

Stack Overflow用户

发布于 2016-09-24 08:30:05

设计支持库有TextInputLayout,当用户开始输入时,它会动态显示提示文本,并将其转换为标签,还可以显示红色错误消息。

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

票数 13
EN

Stack Overflow用户

发布于 2020-09-27 19:07:28

TextInputLayout就是答案。只需使用安卓材料库中的正确版本:https://developer.android.com/reference/com/google/android/material/textfield/TextInputLayout

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

代码语言:javascript
复制
<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>
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3741863

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档