# ChildComponentTest **Repository Path**: cxshu/child-component-test ## Basic Information - **Project Name**: ChildComponentTest - **Description**: 在自定义类中使用子布局 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2021-04-29 - **Last Updated**: 2022-01-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ChildComponentTest 创建一个id为child_layout的DirectionalLayout用来装载子布局 ``` ``` 子布局 ``` ... ``` 新建一个Test类,继承ComponentContainer类 使用LayoutScatter的parse方法生成子布局的对象 ``` Component cptLayout = LayoutScatter.getInstance(context) .parse(ResourceTable.Layout_ability_test, null, false); ``` 把该对象添加到Test组件中 ``` addComponent(cptLayout); ``` 在AbilitySlice中创建Test实例,添加到装载子布局的容器中 ``` Test test = new Test(this); layout.addComponent(test); ```