Android 布局权重按 ImageView 分割

标签 android imageview android-xml

我正在创建一个 Activity 。它有一个主菜单。这是我的 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>

它的输出是这样的;

enter image description here

我想将图像添加到编号区域中。当我添加它们时,这是 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>

输出如下;

enter image description here

布局权重因图像而丢失。我想缩放图像(以其纵横比)并进行布局而不是减轻重量。

我该怎么做?

编辑: @pratik 的回答之后是输出;

enter image description here

最佳答案

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/timerDisplay"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <!-- Current Duration Label -->

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_margin="10dp" >

            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:scaleType="fitXY"
                android:adjustViewBounds="true"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_launcher" />

             <ImageView
                android:id="@+id/imageView2"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:scaleType="fitXY"
                android:adjustViewBounds="true"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_launcher" />

              <ImageView
                android:id="@+id/imageView3"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:scaleType="fitXY"
                android:adjustViewBounds="true"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_launcher" />
        </LinearLayout>

         <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" 
            android:layout_margin="10dp">

            <ImageView
                android:id="@+id/imageView4"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:scaleType="fitXY"
                android:adjustViewBounds="true"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_launcher" />

             <ImageView
                android:id="@+id/imageView5"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:scaleType="fitXY"
                android:adjustViewBounds="true"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_launcher" />

              <ImageView
                android:id="@+id/imageView6"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:scaleType="fitXY"
                android:adjustViewBounds="true"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_launcher" />
        </LinearLayout>
    </LinearLayout>

</LinearLayout>

关于Android 布局权重按 ImageView 分割,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19317745/

相关文章:

android - 从 kotlin 代码中删除 getter 和 setter

java - Android 项目中 getResourceAsStream 的路径

android - 闪烁 imageView 几秒钟

Android - 当背景为 imageview 时,旋转箭头不显示

安卓工作室 : xmlns:map not working

android - 无法将 Samsung Galaxy Tab2 GT- P3100 连接到 PC

android - Hello World Android-错误创建

java - Windows 上的服务器,Android 上的客户端

android - 如何检查哪个图像链接到android中的ImageView?

android - 在 R.attr 中找到正确的样式