文章40 | 阅读 20981 | 点赞0
方法 | 功能 |
---|---|
addAdaptiveRule(int minWidth, int maxWidth, int columns) | 添加一个自适应盒子布局规则 |
removeAdaptiveRule(int minWidth, int maxWidth, int columns) | 移除一个自适应盒子布局规则 |
clearAdaptiveRules() | 移除所有自适应盒子布局规则 |
<?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">
<AdaptiveBoxLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="0vp"
ohos:width="match_parent"
ohos:weight="1"
ohos:id="$+id:adaptive_box_layout">
<Text
ohos:height="40vp"
ohos:width="80vp"
ohos:background_element="#EC9DAA"
ohos:margin="10vp"
ohos:padding="10vp"
ohos:text="NO 1"
ohos:text_size="18fp" />
<Text
ohos:height="40vp"
ohos:width="80vp"
ohos:background_element="#EC9DAA"
ohos:margin="10vp"
ohos:padding="10vp"
ohos:text="NO 2"
ohos:text_size="18fp" />
<Text
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="#EC9DAA"
ohos:margin="10vp"
ohos:padding="10vp"
ohos:multiple_lines="true"
ohos:text="AdaptiveBoxLayout, where a number of boxes with the same width but varied heights are laid out. The height of a row is determined by the highest box."
ohos:text_size="18fp" />
<Text
ohos:height="40vp"
ohos:width="80vp"
ohos:background_element="#EC9DAA"
ohos:margin="10vp"
ohos:padding="10vp"
ohos:text="NO 4"
ohos:text_size="18fp" />
<Text
ohos:height="40vp"
ohos:width="match_parent"
ohos:background_element="#EC9DAA"
ohos:margin="10vp"
ohos:padding="10vp"
ohos:text="Add"
ohos:text_size="18fp" />
<Text
ohos:height="40vp"
ohos:width="80vp"
ohos:background_element="#EC9DAA"
ohos:margin="10vp"
ohos:padding="10vp"
ohos:text="NO 5"
ohos:text_size="18fp" />
<Text
ohos:height="160vp"
ohos:width="80vp"
ohos:background_element="#EC9DAA"
ohos:margin="10vp"
ohos:padding="10vp"
ohos:text="NO 6"
ohos:text_size="18fp" />
</AdaptiveBoxLayout>
<Button
ohos:id="$+id:add_rule_btn"
ohos:layout_alignment="horizontal_center"
ohos:top_margin="10vp"
ohos:padding="10vp"
ohos:background_element="#A9CFF0"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="22fp"
ohos:text="adaptiveBoxLayout.addAdaptiveRule(100, 2000, 3);"/>
<Button
ohos:id="$+id:remove_rule_btn"
ohos:padding="10vp"
ohos:top_margin="10vp"
ohos:layout_alignment="horizontal_center"
ohos:bottom_margin="10vp"
ohos:background_element="#D5D5D5"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="22fp"
ohos:text="adaptiveBoxLayout.removeAdaptiveRule(100, 2000, 3);"/>
</DirectionalLayout>
AdaptiveBoxLayout adaptiveBoxLayout = (AdaptiveBoxLayout)findComponentById(ResourceTable.Id_adaptive_box_layout);
findComponentById(ResourceTable.Id_add_rule_btn).setClickedListener((component-> {
// 添加规则
adaptiveBoxLayout.addAdaptiveRule(100, 2000, 3);
// 更新布局
adaptiveBoxLayout.postLayout();
}));
findComponentById(ResourceTable.Id_remove_rule_btn).setClickedListener((component-> {
// 移除规则
adaptiveBoxLayout.removeAdaptiveRule(100, 2000, 3);
// 更新布局
adaptiveBoxLayout.postLayout();
}));
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/Forever_wj/article/details/118250386
内容来源于网络,如有侵权,请联系作者删除!