typescript - 有没有办法为 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;
});
}
推荐阅读
- python - 没有重复的组合然后将结果分成独特元素的组
- excel - 如何从日期时间值中提取日期以检查两个日期之间的周末?
- php - 单击按钮时复制表单
- pip - 如何将 pip3 命令更改为 pip?对于 Windows
- javascript - 如何将 ColorMatrix 与 Canvas Context 一起应用
- java - 泛型参数化类型返回生成警告或错误
- opencv - opencv VideoWriter录制的视频播放不匀速
- android - 如何在android studio3.2中集成firebase 18.0.0
- python - 将原始时间转换为时区感知时间 (JST)
- javascript - 如何重用 Storybook 的组件故事格式 (CSF) 中的旋钮?