RelativeLayout和高度百分比.无法使用layout_below和layout_weight

dea*_*ish 4 android android-layout

萨吕!我有relativelayout的问题,其子项可以使用layout_below和layout_weight来设置其百分比高度.

例如.我们有相对布局,在内部我们有3个线性布局和textview.现在,我想设置其中3个(线性布局)25,50,25%的相对布局总高度的高度.我该怎么做呢?

我找到了weight_sum和relativelayout(CLICK)的解决方案,但它没有使用layout_below.

请帮忙.我尝试在所有linearlayouts中添加额外的linearlayout,但后来我无法使用layout_below.

这是概念图片的想法: 在此输入图像描述

这是我的代码:

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@+id/linlay_leftcol_notification_header" >

    <LinearLayout
        android:id="@+id/linlay_leftcol_clock_theday"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/tv_theday"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="@string/theday"
        android:textColor="#FFFFFF" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linlay_leftcol_clock_thetime"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/linlay_leftcol_clock_theday" >

        <TextView
            android:id="@+id/tv_thetime"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="@string/thetime"
            android:textColor="#FFFFFF" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linlay_leftcol_clock_thenumber_themonth_theyear"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/linlay_leftcol_clock_thetime" >

        <TextView
            android:id="@+id/tv_thenumberofday_themonth_theyear"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="@string/thenumberofday_themonth_theyear"
            android:textColor="#FFFFFF" />
    </LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

PS请原谅语法,因为我还在学习这门语言.我在帖子之前搜索了解决方案.

Gag*_*gan 12

试试这个......希望这能解决目的.. :-)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:background="#ff00ff"
    android:orientation="vertical">

    <RelativeLayout
        android:layout_weight="1"
        android:background="#ffff00"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/textView0"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:text="Hello 1"
            android:textColor="#000000"
            android:textSize="15dp" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_weight="2"
        android:background="#00ffff"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/textView1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:text="Hello 2"
            android:textColor="#000000"
            android:textSize="15dp" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_weight="1"
        android:background="#ffff00"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/textView2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:text="Hello 3"
            android:textColor="#000000"
            android:textSize="15dp" />
    </RelativeLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)