Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将RelativeLayout划分为3个相同部分_Java_Android_Android Relativelayout - Fatal编程技术网

Java 将RelativeLayout划分为3个相同部分

Java 将RelativeLayout划分为3个相同部分,java,android,android-relativelayout,Java,Android,Android Relativelayout,在我的布局中,我在活动顶部有徽标。 现在我想把我的相对布局分成三个相同的部分,在其中包括3个相对布局。 是否可以为相对布局设置权重? 我如何将其划分为3个相同的相对布局 这是我的密码: <RelativeLayout xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" andr

在我的布局中,我在活动顶部有徽标。 现在我想把我的相对布局分成三个相同的部分,在其中包括3个相对布局。 是否可以为相对布局设置权重? 我如何将其划分为3个相同的相对布局

这是我的密码:

  <RelativeLayout 
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                tools:context=".MainActivity">
<ImageView android:layout_width="wrap_content"
           android:background="@drawable/logo"
           android:id="@+id/logo"
           android:layout_centerHorizontal="true"
           android:layout_height="wrap_content"/>
<RelativeLayout android:layout_width="match_parent"
                android:layout_below="@+id/logo"
                android:layout_height="match_parent">


</RelativeLayout>

</RelativeLayout>

无相关性您不支持权重,只需使用线性布局,即可获得预期结果:

<LinearLayout 
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    orientation:"vertical"
    tools:context=".MainActivity">

    <RelativeLayout
               android:layout_height="0dp"
               android:layout_width="wrap_content"
               android:layout_weight="1">

               <ImageView android:layout_width="wrap_content"
                   android:background="@drawable/logo"
                   android:id="@+id/logo"
                   android:layout_centerHorizontal="true"
                   android:layout_height="wrap_content"/>
    </RelativeLayout>

    <RelativeLayout 
               android:layout_height="0dp"
               android:layout_width="wrap_content"
               android:layout_weight="1">
    </RelativeLayout>

    <RelativeLayout 
               android:layout_height="0dp"
               android:layout_width="wrap_content"
               android:layout_weight="1">
    </RelativeLayout>
</LinearLayout>

如下更改代码:

<LinearLayout
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:context=".MainActivity">
        <ImageView android:layout_width="wrap_content"
                   android:background="@drawable/calender"
                   android:id="@+id/logo"
                   android:layout_centerHorizontal="true"
                   android:layout_height="wrap_content"/>

        <RelativeLayout android:layout_width="match_parent"
                        android:layout_below="@+id/logo"
                        android:layout_weight="1"
                        android:layout_height="0dp">
        </RelativeLayout>

        <RelativeLayout android:layout_width="match_parent"
                        android:layout_below="@+id/logo"
                        android:layout_weight="1"
                        android:layout_height="0dp">
        </RelativeLayout>

        <RelativeLayout android:layout_width="match_parent"
                        android:layout_below="@+id/logo"
                        android:layout_weight="1"
                        android:layout_height="0dp">
        </RelativeLayout>

    </LinearLayout>


请核对答案。这可能对你有用。
<LinearLayout 
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="3"
    orientation:"vertical"
    >

    <RelativeLayout android:layout_height="0dp" android:layout_width="wrap_content" android:layout_weight="1/>
    <RelativeLayout android:layout_height="0dp" android:layout_width="wrap_content" android:layout_weight="1/>
    <RelativeLayout android:layout_height="0dp" android:layout_width="wrap_content" android:layout_weight="1/>

</LinearLayout>