有没有办法为反应本机布局设置纵横比?
Is there any way to set aspect ratio for react-native Layout?
我需要将布局高度设置为其宽度的 60%。 AbsoluteLayout/DockLayout/GridLayout/StackLayout/WrapLayout/FlexboxLayout有吗?
关于我如何实现这一点有什么建议吗?
侦听 layoutChanged
事件,然后测量宽度并应用计算出的高度。
XML
<GridLayout backgroundColor="red" layoutChanged="onLayoutChanged"></GridLayout>
TS
export function onLayoutChanged(args: EventData) {
const gridLayout = <GridLayout>args.object,
height = (layout.toDeviceIndependentPixels(gridLayout.getMeasuredWidth()) / 100) * 60;
gridLayout.off("layoutChanged");
setTimeout(() => {
gridLayout.height = height;
});
}
我需要将布局高度设置为其宽度的 60%。 AbsoluteLayout/DockLayout/GridLayout/StackLayout/WrapLayout/FlexboxLayout有吗?
关于我如何实现这一点有什么建议吗?
侦听 layoutChanged
事件,然后测量宽度并应用计算出的高度。
XML
<GridLayout backgroundColor="red" layoutChanged="onLayoutChanged"></GridLayout>
TS
export function onLayoutChanged(args: EventData) {
const gridLayout = <GridLayout>args.object,
height = (layout.toDeviceIndependentPixels(gridLayout.getMeasuredWidth()) / 100) * 60;
gridLayout.off("layoutChanged");
setTimeout(() => {
gridLayout.height = height;
});
}