android布局重量与相对长度

android布局重量与相对长度,android,android-layout,layout,android-layout-weight,Android,Android Layout,Layout,Android Layout Weight,我是android新手,我有以下问题: 我想把我的屏幕分成4个线性布局,我需要根布局是相对布局, 我尝试使用layout_weight属性,以便在屏幕中平均分割我的4个布局,但只有在将根布局用作线性布局时,我才成功地做到了这一点。 布局xml: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/view_root" android:layout_width=

我是android新手,我有以下问题: 我想把我的屏幕分成4个线性布局,我需要根布局是相对布局, 我尝试使用layout_weight属性,以便在屏幕中平均分割我的4个布局,但只有在将根布局用作线性布局时,我才成功地做到了这一点。 布局xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/view_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:splitMotionEvents="false">

<LinearLayout
    android:id="@+id/top_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1">

    <LinearLayout
        android:id="@+id/a_status_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#5080ce">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="A status"/>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/b_status_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#356dc6">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="B status"/>

    </LinearLayout>
</LinearLayout>

<LinearLayout
    android:id="@+id/bottom_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    >

    <LinearLayout
        android:id="@+id/c_status_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#325287">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="C status"/>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/d_status_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#26477c" >
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="D status"/>
    </LinearLayout>
</LinearLayout>

(^I最后关闭了“RelativeLayout”标记,因为某些原因它没有显示)

(如上面的xml所示)

我可以使用“dp”单位将屏幕拆分为4个,但这样我就遇到了其他问题。。。 我的主要目标是能够将浮动图片从一个版面拖放到另一个版面,我需要使用relativeLayout,另外,我想知道图像被拖放到了哪个版面上,通过使用Rect属性,它会出于某种原因给我错误的位置


非常感谢!:)

只需在两个相对视图的中间添加一个文本视图,属性中心位于父级,顶部将位于该文本视图的上方,线性布局将位于该文本视图的下方,您可以将该文本视图设置为透明或您选择的任何内容(我使用了与前面提到的相同的颜色),请参见下面的代码

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

<LinearLayout
    android:id="@+id/top_layout"
    android:layout_above="@+id/tv_dummy"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1">

    <LinearLayout
        android:id="@+id/a_status_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#5080ce">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="A status" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/b_status_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#356dc6">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="B status" />

    </LinearLayout>
</LinearLayout>

<TextView
    android:id="@+id/tv_dummy"
    android:layout_centerInParent="true"
    android:background="#5080ce"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<LinearLayout
    android:id="@+id/bottom_layout"
    android:layout_below="@+id/tv_dummy"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1">

    <LinearLayout
        android:id="@+id/c_status_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#325287">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="C status" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/d_status_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#26477c">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="D status" />
    </LinearLayout>
</LinearLayout>


只需在两个相对视图的中间添加一个文本视图,属性中心位于父级,顶部将位于该文本视图的上方,线性布局的下方将位于该文本视图的下方,您可以使该文本视图透明或您选择的任何内容(我使用了与前面提到的相同的颜色)参见下面的代码

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

<LinearLayout
    android:id="@+id/top_layout"
    android:layout_above="@+id/tv_dummy"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1">

    <LinearLayout
        android:id="@+id/a_status_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#5080ce">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="A status" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/b_status_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#356dc6">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="B status" />

    </LinearLayout>
</LinearLayout>

<TextView
    android:id="@+id/tv_dummy"
    android:layout_centerInParent="true"
    android:background="#5080ce"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<LinearLayout
    android:id="@+id/bottom_layout"
    android:layout_below="@+id/tv_dummy"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1">

    <LinearLayout
        android:id="@+id/c_status_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#325287">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="C status" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/d_status_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#26477c">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="D status" />
    </LinearLayout>
</LinearLayout>


重量仅适用于线性布局容器。并且加权尺寸必须为0dp。权重仅在线性布局容器中有效。加权尺寸必须为0dp。谢谢!我把高度改为1dp,这样它几乎看不见了!我把高度改为1dp,这样它几乎看不见