【发布时间】:2012-12-15 00:21:57
【问题描述】:
我怎样才能像这样在EditText 上放置按钮:
我只知道如何在EditText 的末尾添加“X”,但我无法根据需要说明如何使用它。当然我说的是安卓。
【问题讨论】:
-
谢谢,这正是我想要的:)
标签: android button android-edittext
我怎样才能像这样在EditText 上放置按钮:
我只知道如何在EditText 的末尾添加“X”,但我无法根据需要说明如何使用它。当然我说的是安卓。
【问题讨论】:
标签: android button android-edittext
如果你想要一个按钮在你的编辑文本的右边,你可以像这样将它包裹在一个水平线性布局中
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/editSearchContact"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button android:id="@+id/xbutton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
如果你想要一个实际的 X 使用图像按钮。
编辑:哦,为了获得更多控制,您可以使用android:weight="" 属性为编辑文本指定屏幕宽度的比例以展开。
【讨论】:
另一个选项(如果我理解你想要什么)是这样的:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- This LinearLayout will be your EditText that holds two Buttons with name and also image-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background" >
<Button
android:id="@+id/the_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="7dp"
android:background="@drawable/draw_the_button"
android:padding="5dp"
android:text="Name Here" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@null"
android:layout_gravity="center_vertical" />
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:src="@android:drawable/ic_input_add"
android:layout_gravity="center_vertical" />
</LinearLayout>
</LinearLayout>
试试看。
【讨论】: