扩展视图的UI

时间:2011-12-28 10:22:19

标签: android user-interface view extend ondraw

我想扩展AutoCompleteTextView的UI。功能很好,我只需要在右边添加一个看起来像下拉按钮的按钮。可悲的是,AutoCompleteTextView具有“自然”余量,我无法将其减少到0。

我现在能做什么? 剂量我必须覆盖onDraw()& onMeasure()归档我的目标(有更简单的方法)吗?

2 个答案:

答案 0 :(得分:0)

您可以将AutoCompleteTextView和按钮放到FrameLayout上,向AutoCompleteTextView添加一些额外的边距,使FrameLayout略大一些,并将按钮对齐到父权。实际上,这2个视图会干扰,但对于用户来说,它们会出现在另一个旁边,没有任何余量 另一个选项可能是将自定义背景设置为AutoCompleteTextView(可能已修改原始版本,取自Android源并删除了边距)。

记得你可以提供负余量。您可以将两个视图放到LinearLayout上,并将按钮的左边距设置为-5dp。但是,您仍然需要为按钮提供自定义无边距背景。

答案 1 :(得分:0)

您可以使用RelativeLayout将Button置于AutoCompleteTextView

的右侧

enter image description here

<强>示例

<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>