结合父级的 wrap_content 和子级的 fill_parent [英] combining wrap_content on parent and fill_parent on child

查看:27
本文介绍了结合父级的 wrap_content 和子级的 fill_parent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将线性布局的两个或多个元素设置为相同的高度似乎是一个大问题.

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" 暂时这样做,但是当其中一个按钮上的文本长于一行时,此按钮会增加,因此比其他按钮大.由于不同的本地化,我不知道何时以及哪个按钮可能会有第二行.

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.

所以我的想法是,将父线性布局设置为 android:layout_height="wrap_content" 并将所有 (!) 子高度设置为 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.

推荐答案

理论上你所描述的不应该工作(因为它的父母从孩子那里得到它的高度,反之亦然".)但是,我们做到了在 LinearLayout 中工作,因为它是一个非常常见的用例.我最近添加了对 FrameLayout 的类似支持(此功能应该是 Honeycomb 的一部分.)因此,您所做的完全有效并且可以正常工作.

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.

这篇关于结合父级的 wrap_content 和子级的 fill_parent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆