Setting two or more elements of a linear layout the same height seems to be a great problem.
I want to set four buttons in a row to the same height.
android:layout_height="wrap_content" does it for the moment but when the text on one of the buttons is longer than one line this button is increased and therefore bigger than the other ones. Due to different localisations I don't know, when and which button may have a second line.
So my idea is, to set the parent linearlayout to android:layout_height="wrap_content" and all (!) child heights to android:layout_height="fill_parent".
This works (all buttons have the same size), but I'm not sure if this causes any other problems? Because it the parent gets it's height from the childs and vice-versa.
Functionally no difference, Google just changed the name from fill_parent to match_parent, from API level 8 (Android 2.2).
For each dimension, it can specify one of: FILL_PARENT (renamed MATCH_PARENT in API Level 8 and higher), which means that the view wants to be as big as its parent (minus padding) WRAP_CONTENT, which means that the view wants to be just big enough to enclose its content (plus padding) an exact number.
fill_parent and match_parent are the same, used when we want the height or width of a view to be as big as its parent view, fill_parent being deprecated. wrap_content is used when we want the view to occupy only as much space as required by it. You may also read : Android UI Layouts.
In theory what you are describing should not work ("Because it the parent gets it's height from the childs and vice-versa".) However, we made it work in LinearLayout because it was a very common use case. I recently added similar support to FrameLayout (this feature should be part of Honeycomb.) What you are doing is therefore perfectly valid and will work just fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With