右边有按钮的Android TextView
嗨,我有一个文本视图,我想在它旁边显示一个按钮。但是layout\u width=“match\u parent”将按钮按出了视图。。。我如何告诉android使用没有按钮的剩余空间右边有按钮的Android TextView,android,layout,Android,Layout,嗨,我有一个文本视图,我想在它旁边显示一个按钮。但是layout\u width=“match\u parent”将按钮按出了视图。。。我如何告诉android使用没有按钮的剩余空间 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:hint="@string/possibility"
android:inputType="textCapSentences"
android:singleLine="true" />
<ImageButton
android:id="@+id/remove"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="@null"
android:src="@drawable/ic_menu_close_clear_cancel" />
</LinearLayout>
通过定义“匹配父对象”,它采用父对象的布局宽度,并且您已经为父对象定义了“填充父对象”,因此EditText具有“填充父对象”属性
这就是为什么你的按钮不见了。如果您没有在线性布局中为小部件赋予权重,请在编辑文本的layout\u width
中使用“wrap\u content”(换行内容
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent" >
<EditText
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/possibility"
android:inputType="textCapSentences"
android:singleLine="true" />
<ImageButton
android:id="@+id/remove"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:src="@drawable/ic_menu_close_clear_cancel"
android:layout_toRightOf="@id/title" />
</RelativeLayout>
</LinearLayout>
我必须等到明天
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent" >
<EditText
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/possibility"
android:inputType="textCapSentences"
android:singleLine="true" />
<ImageButton
android:id="@+id/remove"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:src="@drawable/ic_menu_close_clear_cancel"
android:layout_toRightOf="@id/title" />
</RelativeLayout>
</LinearLayout>