addAdaptiveRule(int minWidth, int maxWidth, int columns)
添加一個自適應盒子布局規則
removeAdaptiveRule(int minWidth, int maxWidth, int columns)
移除一個自適應盒子布局規則
clearAdaptiveRules()
移除所有自適應盒子布局規則
三、場景示例
在 AdaptiveBoxLayout 中添加和刪除自適應盒子布局規則的效果對比如下:
XML 布局示例代碼:
<?xml version="1.0" encoding="utf-8"?><DirectionalLayoutxmlns:ohos="http://schemas.huawei.com/res/ohos"ohos:height="match_parent"ohos:width="match_parent"ohos:orientation="vertical"><AdaptiveBoxLayoutxmlns:ohos="http://schemas.huawei.com/res/ohos"ohos:height="0vp"ohos:width="match_parent"ohos:weight="1"ohos:id="$+id:adaptive_box_layout"><Textohos:height="40vp"ohos:width="80vp"ohos:background_element="#EC9DAA"ohos:margin="10vp"ohos:padding="10vp"ohos:text="NO 1"ohos:text_size="18fp"/><Textohos:height="40vp"ohos:width="80vp"ohos:background_element="#EC9DAA"ohos:margin="10vp"ohos:padding="10vp"ohos:text="NO 2"ohos:text_size="18fp"/><Textohos: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"/><Textohos:height="40vp"ohos:width="80vp"ohos:background_element="#EC9DAA"ohos:margin="10vp"ohos:padding="10vp"ohos:text="NO 4"ohos:text_size="18fp"/><Textohos:height="40vp"ohos:width="match_parent"ohos:background_element="#EC9DAA"ohos:margin="10vp"ohos:padding="10vp"ohos:text="Add"ohos:text_size="18fp"/><Textohos:height="40vp"ohos:width="80vp"ohos:background_element="#EC9DAA"ohos:margin="10vp"ohos:padding="10vp"ohos:text="NO 5"ohos:text_size="18fp"/><Textohos:height="160vp"ohos:width="80vp"ohos:background_element="#EC9DAA"ohos:margin="10vp"ohos:padding="10vp"ohos:text="NO 6"ohos:text_size="18fp"/></AdaptiveBoxLayout><Buttonohos: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);"/><Buttonohos: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>