【问题标题】:How to design the layout using relative layout?如何使用相对布局设计布局?
【发布时间】:2013-10-07 15:19:36
【问题描述】:

在我的 android 应用程序中,我想设计像打击一样的布局

我有四个单独的图像,如下所示

请任何人帮助我了解如何设计此布局。提前致谢

【问题讨论】:

  • 不能使用单张图片吗?

标签: android android-layout android-relativelayout


【解决方案1】:

你可以试试这个..

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

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

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/image1" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/image2" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/image4" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/image3" />
        </LinearLayout>
    </LinearLayout>

</RelativeLayout>

【讨论】:

    【解决方案2】:
    // try this
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:padding="5dp"
                  android:orientation="vertical">
    
        <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="0.25">
            <LinearLayout
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:layout_height="match_parent">
    
                <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:scaleType="fitXY"
                        android:adjustViewBounds="true"
                        android:src="@drawable/ic_launcher"/>
            </LinearLayout>
            <LinearLayout
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:layout_height="match_parent">
    
                <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:scaleType="fitXY"
                        android:adjustViewBounds="true"
                        android:src="@drawable/ic_launcher"/>
            </LinearLayout>
    
        </LinearLayout>
    
        <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="0.75">
            <LinearLayout
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:layout_height="match_parent">
    
                <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:scaleType="fitXY"
                        android:adjustViewBounds="true"
                        android:src="@drawable/ic_launcher"/>
            </LinearLayout>
            <LinearLayout
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:layout_height="match_parent">
    
                <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:scaleType="fitXY"
                        android:adjustViewBounds="true"
                        android:src="@drawable/ic_launcher"/>
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>
    

    【讨论】:

    • 工作正常,但图像之间的空间很大,如何减少它
    • 您可以使用单个图像作为背景并处理每 4 个项目的 onclick,您可以将此布局用作透明视图。
    • @Rajiv Ratan 我想在点击时为每个图像视图设置动画
    • 我刚刚发布了这个答案,因为我无法在此处附加图片。它可能会帮助你。
    【解决方案3】:

    要实现这一点,您需要有 5 组图像。一个是默认的,其他四个就像

    所以onclick图片需要用动画来切换图片。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多