0

In the camera app layout it has:

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>

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> 

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>

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.

Thank you.

phlogratos
  • 13,234
  • 1
  • 32
  • 37
michael
  • 106,540
  • 116
  • 246
  • 346

2 Answers2

1

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

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.

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.

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

jqpubliq
  • 11,874
  • 2
  • 34
  • 26
0

Layout Weight is the relative weight of various layout elements. If one element has weight 1, and others have weight 0, the first element will take all the space available, except the bare minimum needed by the others. If one element has weight 1 and another weight 2, the first takes 1/3 of the space, the other 2/3.

Best regards.

pouzzler
  • 1,800
  • 2
  • 20
  • 32