Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 516
cottonBallPaws Avatar asked Nov 15 '10 21:11

cottonBallPaws


People also ask

How do I make DIV height equal to another div?

The two or more different div of same height can be put side-by-side using CSS. Use CSS property to set the height and width of div and use display property to place div in side-by-side format. The used display property are listed below: display:table; This property is used for elements (div) which behaves like table.

How do you find the height of an element?

In JavaScript, you can use the clientHeight property, which returns an element's height, including its vertical padding. Basically, it returns the actual space used by the displayed content. For example, the following code returns 120, which is equal to the original height plus the vertical padding.

How do I get the height of an element in CSS?

Unfortunately, it is not possible to "get" the height of an element via CSS because CSS is not a language that returns any sort of data other than rules for the browser to adjust its styling. Your resolution can be achieved with jQuery, or alternatively, you can fake it with CSS3's transform:translateY(); rule.


1 Answers

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

like image 160
Falmarri Avatar answered Sep 18 '22 17:09

Falmarri