简体   繁体   English

嵌套线性布局重量

[英]Nested Linear Layout Weight

I have one "Master" LinearLayout with several other LinearLayouts nested inside of it that extend all of the way from side to side. 我有一个“Master”LinearLayout,其中嵌套了几个其他的LinearLayout,它们从一侧延伸到另一侧。 I was wondering if I could use weight to split the vertical space up between the nested layouts with the percentage. 我想知道我是否可以使用重量来分隔嵌套布局与百分比之间的垂直空间。 If so, this could be the solution to all my problems that I am currently having with my app. 如果是这样,这可能是我目前在我的应用程序中遇到的所有问题的解决方案。 All help is appreciated! 所有帮助表示赞赏!

Here is my goal: 这是我的目标: 在此输入图像描述

I want to split those vertically, so it will scale nice. 我想垂直拆分它们,所以它会很好地扩展。

weight of your parent Layout will be count of your total child Layouts and give weight=1 to your child Layouts . 重量你的父母的Layout将是你的孩子总的数量Layouts ,并给予weight=1到你的孩子Layouts

This will align your child Layouts in equal sizes horizontally. 这将使您的子Layouts水平对齐相同的大小。

I would avoid using nested linear layouts. 我会避免使用嵌套的线性布局。 This can severely hinder the apps performance. 这可能会严重阻碍应用程序的性能。 If you find that you are using several nested linear layouts, you might want to consider using a relative layout. 如果您发现使用多个嵌套线性布局,则可能需要考虑使用相对布局。 Of course, with relative layout's, you can't use the "weight" attribute, but there are ways around that. 当然,对于相对布局,你不能使用“权重”属性,但有办法解决这个问题。 Here is a great article that talks about layouts: 这是一篇很好的文章,讨论布局:

http://android-developers.blogspot.com/2009/02/android-layout-tricks-1.html http://android-developers.blogspot.com/2009/02/android-layout-tricks-1.html

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

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