-4

I need to do an layout in which 4 images are shown in a box in different sizes using XML.

Layout

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 using weights and weightsum, but there was no success.

     <LinearLayout
                        android:layout_width="fill_parent"
                        android:layout_height="300dp"
                        android:layout_margin="10dp" >

                        <ImageView
                            android:layout_width="0dp"
                            android:layout_height="fill_parent"
                            android:layout_weight="1"
                            android:src="@drawable/image1" />

                        <ImageView
                            android:layout_width="0dp"
                            android:layout_height="fill_parent"
                            android:layout_weight="1"
                            android:src="@drawable/image2" />

 <ImageView
                            android:layout_width="0dp"
                            android:layout_height="fill_parent"
                            android:layout_weight="2"
                            android:src="@drawable/image3" />

 <ImageView
                            android:layout_width="0dp"
                            android:layout_height="fill_parent"
                            android:layout_weight="2"
                            android:src="@drawable/image4" />
                    </LinearLayout>
Luuklag
  • 3,897
  • 11
  • 38
  • 57
Johnny2012
  • 1,512
  • 8
  • 31
  • 46

1 Answers1

2

Here an example:

<?xml version="1.0" encoding="utf-8"?>

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

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/imageView"
        android:layout_weight="1" />

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:weightSum="2">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/imageView2"
            android:layout_weight="1" />

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:weightSum="2">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/imageView3"
                android:layout_weight="1" />

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/imageView4"
                android:layout_weight="1" />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>
adboco
  • 2,840
  • 1
  • 21
  • 21