Questions tagged [android-layout-weight]

In Android by setting a layout_weight for the Views inside the LinearLayout, the parent layout divides the available space between its children according to their weights.

Description

Indicates how much of the extra space in the LinearLayout will be allocated to the view associated with these LayoutParams.

By setting a layout_weight for the Views inside the LinearLayout, the parent layout divides the available space between its children according to their weights.

Implementation

A Vertical LinearLayout with 2 Views. Top View has layout_weight of 3 and bottom one has 1, which means total of 4. Top View will fill 3/4 of the Layout and bottom one will fill 1/4 of the Layout.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <View
        android:id="@+id/view1"
        android:layout_width="match_parent"
        android:layout_height="0px"
        android:layout_weight="3"/>

    <View
        android:id="@+id/view2"
        android:layout_width="match_parent"
        android:layout_height="0px"
        android:layout_weight="1"/>    

</LinearLayout>

Link

Android Developers

451 questions
-4
votes
1 answer

How to do a layout with 4 images in different sizes in Android?

I need to do an layout in which 4 images are shown in a box in different sizes using XML. The box is a linearLayout with a fixed height 300dp and fill_parent in the width. It is not a Requirement to do this using a LinearLayout. I tried to do it…
Johnny2012
  • 1,512
  • 8
  • 31
  • 46
1 2 3
30
31