-4

我需要做一个布局,其中 4 个图像使用 XML 以不同大小显示在一个框中。

布局

该框是一个线性布局,高度固定为300dp,宽度为fill_parent。不需要使用 LinearLayout 来执行此操作。

我尝试使用权重和权重来做到这一点,但没有成功。

     <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>
4

1 回答 1

2

这里有一个例子:

<?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>
于 2014-06-11T12:33:24.577 回答