android - android:背景没有反映在布局权重的视图中
问题描述
我有一个简单LinearLayout
的ImageView
视图和普通视图,布局权重分别为 0.55 和 0.45。
除非我给weightsum
我的LinearLayout
.
拆分后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>
推荐阅读
- sql-server - 新手:为 SQL Server 2017 创建 dockerfile
- c++ - 了解获取非静态成员地址以形成指向成员函数的指针的错误?
- javascript - 如何使滚动到顶部的动作更流畅
- r - R中是否有一个函数允许选择行名以小写字母结尾的行并删除该字母?
- typescript - OR 运算符如何在 javascript 或 typescript 中查找函数?
- regex - 查找范围内的字符
- angular - 如何使用 angular dart webdev 在 localhost 上建立安全连接?
- html - 如何顺利地做CSS动画而不中断
- ios - UISwitch 值更改状态问题
- angular - 用文本控件替换字符串并在 angular4+ 中从中获取值