需要帮助理解layout_weight =" 1 QUOT; [英] Need help in understand layout_weight="1"

查看:103
本文介绍了需要帮助理解layout_weight =" 1 QUOT;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在相机应用的布局有:

camera.xml:

camera.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/app_root"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<include layout="@layout/preview_frame"/>
<include layout="@layout/camera_control"/>
</LinearLayout>

和preview_frame.xml是

and preview_frame.xml is

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/frame_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1">
    .....
</RelativeLayout> 

和camera_control.xml是:

and camera_control.xml is:

<ControlPanelLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/control_panel"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="76dp"
    android:background="@drawable/bg_camera_pattern">
    .....
 </ControlPanelLayout>

我的问题是什么是'layout_weight =1在preview_frame.xml呢?
我看了一下layout_weight但大部分与layout_width =0像素使用的时间
而在camera_control,它没有指定的任何layout_weight有。

My question is what is the 'layout_weight="1" ' in preview_frame.xml for? I have read about layout_weight but most of the time it used with layout_width="0px" And in camera_control, it does not have any layout_weight specified.

但是,在这种情况下,它不是

But in this case, it is not.

感谢您。

推荐答案

布局重量决定如何毕竟增加的观点已经采取了他们的基本区父任何剩余的空间被填满。

Layout weight decides how any remaining space in the parent is filled after all the added views have taken up their basic area.

的一个的ViewGroup视图的权重相加并且剩余的空间被按比例划分。因此,与宽度0和权重1和2两个视图将总结到权重为3和一个视图将扩大到视图尺寸的1/3,另2/3。

The weights of the views in a viewgroup are added up and the leftover space is divided proportionally. So two views with width 0 and weights 1 and 2 will sum to a weight of 3 and one view will expand to 1/3 of the view size and the other to 2/3.

不过,如果有意见的宽度,它们会占用发放额外的空间之前的空间。所以,宽度和没有重量的图会占用分配的空间和一个加权视图旁边将填满剩余,因此在权重1和2中提供了previous例如如果该重量体1视图的宽度,它将扩大到另外包括剩余的空间,可以把它放在比重量2查看大图的1/3。

However if views have width, they will take up that space before handing out the extra space. So a view with a width and no weight will take up the allotted space and a weighted view beside it will fill the remainder, so in our previous example of weights 1 and 2 if the weight 1 view has a width, it will expand to additionally include 1/3 of the REMAINING space which could put it at being larger than the weight 2 view.

有点消沉,还没有我的咖啡,但我希望它可以帮助你:P

A little unfocused, haven't had me coffee,but I hope it helps you out :P

这篇关于需要帮助理解layout_weight =&QUOT; 1 QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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