扩展视图的 UI
我想扩展 AutoCompleteTextView 的 UI。功能很好,我所需要的只是在右侧添加一个看起来像下拉按钮的按钮。遗憾的是 AutoCompleteTextView 有一个“自然”边距,我无法将其减少到 0。
我现在能做什么? 我必须重写 onDraw() & onMeasure() 来存档我的目标(有更简单的方法吗)?
I would like to extend the UI of AutoCompleteTextView. The Functionality is fine, all I need is to add an button to the right that looks like a drop-down button. Sadly AutoCompleteTextView has a 'natural' margin that I can't reduce to 0.
What can I do now?
Dose I have to overwrite onDraw() & onMeasure() to archive my goal (is there an easier way)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将
AutoCompleteTextView
和按钮都放在FrameLayout
上,在AutoCompleteTextView
右侧添加一些额外的边距,以使FrameLayout
稍大一些,并将按钮对齐到父级右侧。事实上,这两个视图会产生干扰,但对于用户来说,它们将出现在另一个视图旁边,没有任何边距。另一种选择是将自定义背景设置为 AutoCompleteTextView(可能是从 Android 源代码中获取的原始背景,并删除了边距)。
只需记住您可以提供负保证金。例如,您可以将两个视图都放在
LinearLayout
上,并将按钮的左边距设置为-5dp
。但是,您仍然需要为按钮提供自定义无边距背景。You could put both
AutoCompleteTextView
and button ontoFrameLayout
, add some extra margin right toAutoCompleteTextView
to makeFrameLayout
slightly bigger, and align button to parent right. In fact, these 2 views will interfere, but for user they will appear one next to the other w/o any margin.Another option could be to set custom background to
AutoCompleteTextView
(probably modified original one taken from Android source with removed margin).Just remembered that you can supply negative margin. You can put both views onto
LinearLayout
and set left margin of button to-5dp
for example. However, you will still have to supply custom marginless background for button.您可以使用
RelativeLayout
将 Button 放置在AutoCompleteTextView
右侧示例
you can use
RelativeLayout
to put Button to the right ofAutoCompleteTextView
Sample