You can use LayoutScatter.getInstance(Context context).parse(int xmlId, ComponentContainer root, boolean attachToRoot)
to implement this.
The following is the sample code for your reference:
<DirectionalLayout
ohos:id="$+id:root_dir_layout"
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:orientation="vertical"
>
</DirectionalLayout>
private void initView() {
if (findComponentById(ResourceTable.Id_root_dir_layout)!= null &&
findComponentById(ResourceTable.Id_root_dir_layout) instanceof DirectionalLayout) {
rootDirectionalLayout = (DirectionalLayout) findComponentById(ResourceTable.Id_root_dir_layout);
DirectionalLayout contentComponent = (DirectionalLayout) LayoutScatter.getInstance(
getContext()).parse(ResourceTable.Layout_dialog_delete, null, false);
rootDirectionalLayout.addComponent(contentComponent);
}
}
For more details, pls kindly refer to Docs.