android - Android - layout_weight - LinearLayout 中的大小问题
问题描述
我需要创建一个具有一定纵横比并且具有响应性的布局。
块将被放置在另一个之上。我需要在以下命题中定义组件: Block 1:10% Block 2:5% Block 3:60% Block 4:15% Block 5:10%
这是我的模板的样子:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/l0"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/l1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/holo_red_dark"
android:orientation="horizontal"></LinearLayout>
<LinearLayout
android:id="@+id/l2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/holo_blue_dark"
android:orientation="horizontal"></LinearLayout>
<LinearLayout
android:id="@+id/l3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/holo_green_dark"
android:orientation="horizontal"></LinearLayout>
<LinearLayout
android:id="@+id/l4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/holo_purple"
android:orientation="horizontal"></LinearLayout>
<LinearLayout
android:id="@+id/l5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/holo_orange_dark"
android:orientation="horizontal"></LinearLayout>
</LinearLayout>
我尝试通过 layout_weight 确定: 块 1:1 或 10 块 2:0.5 或 5 块 3:6 或 60 块 4:1.5 或 15 块 5:1 或 10
但一切都崩溃了。
它是如何工作的?我究竟做错了什么?
解决方案
android:layout_height="0dp"
如果父项的方向是垂直的,则必须设置为所有子项
推荐阅读
- javascript - 不可变地更新对象列表中的对象列表
- algorithm - 切换数组中的位对以最大化其与另一个数组的点积
- java - 如何勾选“按pdf页面大小选择纸张来源”iText7?
- android - 如何为 iOS 强制颤动设备方向
- git - git有某种缓存机制吗?
- python-3.x - 问题 - 使用 sentinelsat 提取卫星图像
- ios - iOS13之前如何访问UIImage深色外观
- post - 在 HttpWebRequestMessage 中找不到正文
- flutter - 如何换行一行文本?
- java - java - 如何比较两个对象,每个对象都包含基本类型和java中的对象集合?