2

アクティビティを作成しています。メインメニューがあります。これが私のxmlです。

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical" >

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="4"
        android:orientation="horizontal" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="8" >

        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="84"
            android:background="@drawable/main_menu_background_shape"
            android:orientation="vertical" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1" >

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:orientation="vertical" >

                </LinearLayout>

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:orientation="vertical" >

                </LinearLayout>

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:orientation="vertical" >

                </LinearLayout>

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1" >

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:orientation="vertical" >

                </LinearLayout>

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:orientation="vertical" >

                </LinearLayout>

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:orientation="vertical" >

                </LinearLayout>

            </LinearLayout>

        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="8" >

        </LinearLayout>

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical" >

    </LinearLayout>

</LinearLayout>

そして、次のように出力されます。

ここに画像の説明を入力

番号付きの領域に画像を追加したい。それらを追加すると、ここにxmlがあります。

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical" >

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="4"
        android:orientation="horizontal" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="8" >

        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="84"
            android:background="@drawable/main_menu_background_shape"
            android:orientation="vertical" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1" >

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:orientation="vertical" >

                    <ImageView
                        android:id="@+id/imageView1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:adjustViewBounds="true"
                        android:src="@drawable/main_menu_katilimcilar" />

                </LinearLayout>

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:orientation="vertical" >

                    <ImageView
                        android:id="@+id/imageView3"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@drawable/main_menu_etkinlikler" />

                </LinearLayout>

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:orientation="vertical" >

                    <ImageView
                        android:id="@+id/imageView4"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@drawable/main_menu_imza_gunleri" />

                </LinearLayout>

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1" >

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:orientation="vertical" >

                    <ImageView
                        android:id="@+id/imageView5"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@drawable/main_menu_fuar_haritasi" />

                </LinearLayout>

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:orientation="vertical" >

                    <ImageView
                        android:id="@+id/imageView6"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@drawable/main_menu_fuar_hakkinda" />

                </LinearLayout>

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:orientation="vertical" >

                    <ImageView
                        android:id="@+id/imageView7"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@drawable/main_menu_paylas" />

                </LinearLayout>

            </LinearLayout>

        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="8" >

        </LinearLayout>

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical" >

    </LinearLayout>

</LinearLayout>

このような出力;

ここに画像の説明を入力

画像のためにレイアウトの重みが失われました。画像を(アスペクト比で)スケーリングし、重量を失わないようにレイアウトを作成したい。

どうすればいいですか?

編集: @pratikの回答の後、ここに出力があります。

ここに画像の説明を入力

4

3 に答える 3

0

以下のようにしてみてください。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rl"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/ll"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum=".9" >

        <ImageView
            android:id="@+id/frame3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight=".3"
             android:scaleType="fitXY"
            android:adjustViewBounds="true"
            android:src="@drawable/ic_launcher" />

        <ImageView
            android:id="@+id/frame2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight=".3"
            android:scaleType="fitXY"
            android:adjustViewBounds="true"
            android:src="@drawable/ic_launcher" />

        <ImageView
            android:id="@+id/frame1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight=".3"
            android:scaleType="fitXY"
            android:adjustViewBounds="true"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>

    <LinearLayout
        android:layout_marginTop="20dp"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/ll"
        android:orientation="horizontal"
        android:weightSum=".9" >

        <ImageView
            android:id="@+id/frame3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight=".3"
             android:scaleType="fitXY"
            android:adjustViewBounds="true" 
            android:src="@drawable/ic_launcher" />

        <ImageView
            android:id="@+id/frame2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight=".3"
            android:scaleType="fitXY"
            android:adjustViewBounds="true"
            android:src="@drawable/ic_launcher" />

        <ImageView
            android:id="@+id/frame1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight=".3"
             android:scaleType="fitXY"
            android:adjustViewBounds="true"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>

</RelativeLayout>
于 2013-10-11T12:27:27.227 に答える