android:background 布局权重未反映在视图中

android:background not reflected in view with layout weight

我有一个简单的 LinearLayout,它有一个 ImageView 和一个布局权重分别为 0.55 和 0.45 的普通视图。

除非我给 LinearLayout 一个 weightsum,否则我无法拆分。

LinearLayout 拆分后,我尝试为 我的观点,但它没有反映。

下面是我的代码:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="1"
    >
    <ImageView
        android:layout_weight=".55"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="5dip"
        android:scaleType="fitXY"
        android:src="@drawable/ic_launcher_background"
        android:contentDescription="TODO" />

    <View
        android:layout_weight=".45dp"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:visibility="visible"
        android:background="@color/colorPrimary"
        ></View>

</LinearLayout>

我不明白应该改成什么,我可以拆分意见 正确设置背景颜色。提前致谢!

"android:layout_weight=".45dp"替换为"android:layout_weight=".45"

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">

<ImageView
    android:layout_weight=".55"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_marginTop="5dip"
    android:scaleType="fitXY"
    android:src="@drawable/ic_launcher_background"
    android:contentDescription="TODO" />

 <View
    android:layout_weight=".45"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:visibility="visible"
    android:background="@color/colorPrimary"/>


</LinearLayout>