智能客服
你问我答,随时在线为你解决问题
| |---ohos.agp.components.Component |---|---ohos.agp.components.ComponentContainer |---|---|---ohos.agp.components.AdaptiveBoxLayout public class AdaptiveBoxLayout extends ComponentContainer |
An adaptive box layout is automatically divided into rows and columns of boxes with the same width and possibly different heights. The width of the boxes depends on the layout width and the number of boxes in each row, which is specified by the layout policy. A new row starts only after the previous row is filled. Each box contains a child component. The height of each box is determined by the height of the child component it contains. The height of each row is determined by the highest box in this row. The width of the layout can only be set to MATCH_PARENT or a fixed value. The length, width, and alignment mode can be set for the components in the layout.
Since:
3Modifier and Type | Class | Description |
|---|---|---|
static class | Defines layout parameters for child components in an AdaptiveBoxLayout instance, including their width, height, margins, and gravity. |
Nested classes/interfaces inherited from class ohos.agp.components.ComponentContainer |
|---|
Fields inherited from class ohos.agp.components.ComponentContainer |
|---|
FOCUS_CHILDREN_FIRST, FOCUS_CHILDREN_HIDE, FOCUS_PARENT_FIRST, mArrangeListener |
Constructor | Description |
|---|---|
AdaptiveBoxLayout(Context context) | Default constructor used to create a AdaptiveBoxLayout instance by using the default attribute set and style. |
AdaptiveBoxLayout(Context context, AttrSet attrSet) | A constructor used to create a AdaptiveBoxLayout instance by using specified attribute set and default style after the XML file is parsed. |
AdaptiveBoxLayout(Context context, AttrSet attrSet, String styleName) | A constructor used to create a AdaptiveBoxLayout instance by using specified attribute set and specified style after the XML file is parsed. |
Modifier and Type | Method | Description |
|---|---|---|
void | addAdaptiveRule(int minWidth, int maxWidth, int columns) | Adds an adaptive rule that dictates the number of boxes allowed in each row in a layout whose width falls within the specified range. |
void | Clears all adaptive rules. | |
createLayoutConfig(Context context, AttrSet attrSet) | Creates layout parameters using the attribute set of a child component. | |
void | removeAdaptiveRule(int minWidth, int maxWidth, int columns) | Removes a specified rule. |
Verifies layout parameters based on the current layout type. |
Methods inherited from interface ohos.agp.components.ComponentParent |
|---|
public AdaptiveBoxLayout(Context context)
Default constructor used to create a AdaptiveBoxLayout instance by using the default attribute set and style.Parameters:
Parameter Name | Parameter Description |
|---|---|
context | Indicates the application context. |
public AdaptiveBoxLayout(Context context, AttrSet attrSet)
A constructor used to create a AdaptiveBoxLayout instance by using specified attribute set and default style after the XML file is parsed.Parameters:
Parameter Name | Parameter Description |
|---|---|
context | Indicates the application context. |
attrSet | Indicates the attribute set to be used. |
public AdaptiveBoxLayout(Context context, AttrSet attrSet, String styleName)
A constructor used to create a AdaptiveBoxLayout instance by using specified attribute set and specified style after the XML file is parsed.Parameters:
Parameter Name | Parameter Description |
|---|---|
context | Indicates the application context. |
attrSet | Indicates the attribute set to be used. |
styleName | Indicates the style name to use. |
public void addAdaptiveRule(int minWidth, int maxWidth, int columns)
Adds an adaptive rule that dictates the number of boxes allowed in each row in a layout whose width falls within the specified range.If the width of a layout falls with the range defined by an adaptive rule, this rule applies. Otherwise, the default rule applies.
Parameters:
Parameter Name | Parameter Description |
|---|---|
minWidth | Indicates the minimum width for the rule to take effect. |
maxWidth | Indicates the maximum width for the rule to take effect. This value must be greater than the value of minWidth. Otherwise, the rule cannot be added. |
columns | Indicates the number of boxes allowed in each row. The value must be greater than 0. Otherwise, the rule cannot be added. |
Throws:
Throw Name | Throw Description |
|---|---|
Throws this exception if the rule can't be added due to invalid parameters. |
public void clearAdaptiveRules()
Clears all adaptive rules.The default rule applies after all adaptive rules are cleared.
public void removeAdaptiveRule(int minWidth, int maxWidth, int columns)
Removes a specified rule.Parameters:
Parameter Name | Parameter Description |
|---|---|
minWidth | Indicates the minimum width for the rule to take effect. |
maxWidth | Indicates the maximum width for the rule to take effect. |
columns | Indicates the number of columns allowed in each row. |
Since:
4
public ComponentContainer.LayoutConfig verifyLayoutConfig(ComponentContainer.LayoutConfig config)
Description copied from class: ComponentContainerVerifies layout parameters based on the current layout type.
Specified by:
verifyLayoutConfig in interface ComponentParent
Overrides:
verifyLayoutConfig in class ComponentContainer
Parameters:
Parameter Name | Parameter Description |
|---|---|
config | Indicates a group of layout parameters to be converted into a ComponentContainer instance. |
Returns:
Returns the LayoutConfig instance, which represents the layout parameters.
public ComponentContainer.LayoutConfig createLayoutConfig(Context context, AttrSet attrSet)
Description copied from class: ComponentContainerCreates layout parameters using the attribute set of a child component.
Overrides:
createLayoutConfig in class ComponentContainer
Parameters:
Parameter Name | Parameter Description |
|---|---|
context | Indicates the application context. |
attrSet | Indicates the attribute set. |
Returns:
Returns the layout parameters created.