布局:
继承结果:布局是一种特殊的容器类组件
接下来,我们先来看线性布局:
也可以通过代码改为水平方向
接下来,代码演示权重该如何使用
ability_main.xml代码:
<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:orientation="vertical">
<Button
ohos:height="0vp"
ohos:width="100vp"
ohos:text="点我1"
ohos:text_size="35fp"
ohos:text_color="#FFFFFF"
ohos:text_alignment="center"
ohos:background_element="#21a8fd"
ohos:weight="2"/>
<Button
ohos:height="0vp"
ohos:width="100vp"
ohos:text="点我2"
ohos:text_size="35fp"
ohos:text_color="#FFFFFF"
ohos:text_alignment="center"
ohos:background_element="#ff0000"
ohos:weight="1"/>
<Image
ohos:height="match_content"
ohos:width="match_content"
ohos:image_src="$media:girl6"/>
</DirectionalLayout>
运行效果: