我想要一些像这样的布局
[text tabel][edittext]我找不到像html esque标签这样的属性。这似乎是我需要使用的情况
[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" />
发布于 2010-09-18 21:31:35
你基本上有两个选择:
选项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>发布于 2016-09-24 08:30:05
设计支持库有TextInputLayout,当用户开始输入时,它会动态显示提示文本,并将其转换为标签,还可以显示红色错误消息。
https://developer.android.com/reference/android/support/design/widget/TextInputLayout.html
发布于 2020-09-27 19:07:28
TextInputLayout就是答案。只需使用安卓材料库中的正确版本:https://developer.android.com/reference/com/google/android/material/textfield/TextInputLayout
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>https://stackoverflow.com/questions/3741863
复制相似问题