简体   繁体   English

android嵌套layout_weights

[英]android nested layout_weights

I'd like to have the effect of LinearLayout Horizontal inside LinearLayout Vertical. 我想在LinearLayout Vertical中使用LinearLayout Horizo​​ntal的效果。 The problem is I want to have layout_weights for Views in the Horizontal layout and layout_weights for the Views in the Vertical one. 问题是我希望在水平布局中为视图设置layout_weights,为垂直视图中的视图设置layout_weights。 It works, but in eclipse I get a warning that it's inefficient and that I shouldn't use layout_weights one in another. 它可以工作,但在日食中我得到一个警告,它是低效的,我不应该使用layout_weights。


This is what I did: 这就是我做的:

LinearLayout中的LinearLayout

In the horizontal LinearLayout each button got a layout_weight of 1 and in the vertical LinearLayout, each inner View got a certain weight as well. 在水平LinearLayout中,每个按钮的layout_weight为1,在垂直LinearLayout中,每个内部视图也有一定的权重。

Is there a way to do this effect in some other way and keep it flexible to look good in all the devices? 有没有办法以其他方式实现这种效果并保持灵活性以便在所有设备中都看起来很好? I don't plan on using GridLayout because I want to support older devices running android. 我不打算使用GridLayout,因为我想支持运行android的旧设备。

It is just a warning. 这只是一个警告。 If you will not continue to wrap the LinearLayout in another one with weigths and so on, maybe you can ignore this warning. 如果你不能继续将LinearLayout包装在另一个带weigths等的情况下,也许你可以忽略这个警告。 Using layout_weight is bad for performance because AFAIK it will cause each widget to be measured twice, than each widget inside it to be measured again twice and so on. 使用layout_weight对性能不利,因为AFAIK会导致每个widget被测量两次,而其中的每个widget要再次测量两次,依此类推。

If you do not see performance issues with your layout, I think you can keep it, because I can`t see other ways to achieve this. 如果您没有看到布局的性能问题,我认为您可以保留它,因为我无法看到实现此目的的其他方法。

Alternatively, there is also a backward compatible GridLayout if you want to consider using it. 或者,如果您想考虑使用它,还有一个向后兼容的GridLayout

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM