Nativescript 如何从定义的布局字符串从js设置gridlayout
我试图在xml中设置一个网格布局,如下所示Nativescript 如何从定义的布局字符串从js设置gridlayout,nativescript,Nativescript,我试图在xml中设置一个网格布局,如下所示 layout: `<GridLayout row="0" rows="*, 2*, *"> <GridLayout width="57%" row="0" horizontalAlignment="center" verticalAlignment="center"> <Label class="lobster-regular carousel-item-head
layout: `<GridLayout row="0" rows="*, 2*, *">
<GridLayout width="57%" row="0" horizontalAlignment="center" verticalAlignment="center">
<Label class="lobster-regular carousel-item-head" text="Welcome to Payments App" textWrap="true"></Label>
</GridLayout>
<GridLayout class="carousel-item-circle" row="1" horizontalAlignment="center" verticalAlignment="center">
<Label class="fa carousel-item-icon" text="" textWrap="true"></Label>
</GridLayout>
<GridLayout width="49%" row="2" horizontalAlignment="center" verticalAlignment="center">
<Label class="opensans-regular carousel-item-desc" text="Let's see a quick overview of our features." textWrap="true"></Label>
</GridLayout>
</GridLayout>
`,
请给我详细的建议和答案或替代方案来实现这一点。使用
const布局=`
`;
const builder=require(“tns核心模块/ui/builder”);
const gridLayout=builder.parse(布局);
myScroll.content=gridLayout;
myScroll元素从来都不是UI的一部分,您应该先将其添加到UI中吗<代码>page.content=myScroll代码>-
const myScroll = new ScrollView();
myScroll.orientation = "vertical";
console.log(homeViewModel.layout);
myScroll.content = homeViewModel.layout;
const layout = `<GridLayout row="0" rows="*, 2*, *">
<GridLayout width="57%" row="0" horizontalAlignment="center" verticalAlignment="center">
<Label class="lobster-regular carousel-item-head" text="Welcome to Payments App" textWrap="true"></Label>
</GridLayout>
<GridLayout class="carousel-item-circle" row="1" horizontalAlignment="center" verticalAlignment="center">
<Label class="fa carousel-item-icon" text="" textWrap="true"></Label>
</GridLayout>
<GridLayout width="49%" row="2" horizontalAlignment="center" verticalAlignment="center">
<Label class="opensans-regular carousel-item-desc" text="Let's see a quick overview of our features." textWrap="true"></Label>
</GridLayout>
</GridLayout>
`;
const builder = require("tns-core-modules/ui/builder");
const gridLayout = builder.parse(layout);
myScroll.content = gridLayout;