Android 机器人与重量

Android 机器人与重量,android,Android,为什么下面的代码只显示两种颜色而不是三种?如何解决这个问题 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_heigh

为什么下面的代码只显示两种颜色而不是三种?如何解决这个问题

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

    <LinearLayout
        android:background="#00ff00"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:layout_weight="3" />

    <LinearLayout
        android:background="#ff0000"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:layout_weight="2" />

    <LinearLayout
        android:background="#0000ff"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:layout_weight="1" />

</LinearLayout>

将每个
线性布局中的
布局高度更改为0:

android:layout_height="0dp"
任何其他高度都会妨碍Android根据权重计算每个布局的空间大小


你想做什么?使用
android:layout\u weight
而不指定
android:layout\u height=“0dp”
不会有任何作用。