How to get a button's height to match another element's height?

cottonBallPaws picture cottonBallPaws · Nov 15, 2010 · Viewed 51.7k times · Source

I want to put a button next to a EditText and I want their heights to match.

For example, from the built in Android browser:

alt text

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.

Is this possible with an xml layout?

Answer

Falmarri picture Falmarri · Nov 15, 2010

Presumably the EditText and the Button are inside a RelativeLayout. Set the button's layout attributes to alignTop and alignBottom of the EditText.