如何获取按钮的高度以匹配另一个元素的高度? [英] How to get a button's height to match another element's height?
问题描述
我想在EditText旁边放置一个按钮,并且希望它们的高度匹配.
I want to put a button next to a EditText and I want their heights to match.
例如,通过内置的Android浏览器:
For example, from the built in Android browser:
转到"按钮的高度与EditText字段的高度相同.我知道我可以将这两个视图都包装在父布局视图中,并将它们的两个高度都设置为fill_parent,这将使它们匹配.但是,我想这样做而不必给布局提供静态大小.我宁愿让EditText根据字体大小获取所需的高度,然后使其旁边的按钮与可能的高度匹配.
The Go button is the same height as the EditText field. I know I could wrap both these views in a parent layout view, and set both of their heights to fill_parent, and that would make them match. However, I would like to do this without having to give the layout a static size. I would rather have the EditText take whatever height it needs based on the font size and then have the button next to it match whatever height that might be.
使用xml布局可能吗?
Is this possible with an xml layout?
推荐答案
您需要将EditText
wrap_content
设置为高度并将Button
设置为fill_parent
.您将需要将它们都包装在Layout
父级中.这样,它们便与同一个Layout
父级关联.
You will need to make the EditText
wrap_content
on its height and have the Button
just fill_parent
. You will need to have them both wrapped in a Layout
parent. That way they are associated with the same Layout
parent.
尝试一下,看看它如何工作(如果有帮助的话,请告诉我).如果没有,我可以给您一些代码来帮助您.
Try that and see how that works, if it helps let me know. If it doesn't maybe i can give you some code that will help you out.
这篇关于如何获取按钮的高度以匹配另一个元素的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!