combining wrap_content on parent and fill_parent o

2019-01-10 12:24发布

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.

2条回答
Evening l夕情丶
2楼-- · 2019-01-10 13:09

That doesn't make sense :(

Why don't you use android:singleLine="true" and some ellipsode?

查看更多
闹够了就滚
3楼-- · 2019-01-10 13:19

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.

查看更多
登录 后发表回答