我想扩展AutoCompleteTextView的UI。功能很好,我需要的只是在右侧添加一个按钮,看起来像一个下拉按钮。可悲的是AutoCompleteTextView有一个'自然'的边际,我不能减少到0.扩展视图的UI
我现在能做什么? 我必须覆盖onDraw()& onMeasure()来存档我的目标(是否有更简单的方法)?
我想扩展AutoCompleteTextView的UI。功能很好,我需要的只是在右侧添加一个按钮,看起来像一个下拉按钮。可悲的是AutoCompleteTextView有一个'自然'的边际,我不能减少到0.扩展视图的UI
我现在能做什么? 我必须覆盖onDraw()& onMeasure()来存档我的目标(是否有更简单的方法)?
你可以把两者AutoCompleteTextView
和按钮拖到FrameLayout
,添加一些额外的保证金权利AutoCompleteTextView
使FrameLayout
稍大,并对齐按钮父权。实际上,这两个视图会干扰,但对于用户而言,它们将在没有任何边距的情况下出现在另一个旁边。
另一种选择可能是将自定义背景设置为AutoCompleteTextView
(可能是修改了从Android源获取的原始内容并删除了边距)。
只记得你可以提供负利润率。例如,您可以将两个视图都放到LinearLayout
上,并将按钮的左边距设置为-5dp
。但是,您仍然必须为按钮提供自定义无边框背景。
可以使用RelativeLayout
把按钮的AutoCompleteTextView
样品
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/btn_close_pressed"
android:layout_alignParentRight="true"
android:id="@+id/myBtn"
></Button>
<AutoCompleteTextView android:id="@+id/myautocomplete"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:completionThreshold="1"
android:layout_toLeftOf="@+id/myBtn"
/>
</RelativeLayout>
设置自定义背景右边是解决我的XML问题( '形状'有几个属性)。 – Klau3 2011-12-28 11:09:36