flutter - 颤振不同的轴单元
问题描述
如何处理使用多种单位类型(空间百分比、像素数等)来调整小部件的大小?一个等效的 CSS 示例是div{width: 70%; height: 50px}
解决方案
可以做这样的事情:
Container(
width: MediaQuery.of(context).size.width * 0.50, // this would be 50% of screen width
height: 50,
)
另一种选择是:
LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
return Container(
width: constraints.maxWidth * 0.50, // 50% of parent size
height: 50,
);
}
)
更多信息:按屏幕宽度/高度百分比调整元素大小
推荐阅读
- c# - 如何制作使用 oninput 而不是 onchange 绑定的 EditForm 输入?
- keras - 在网络摄像头视频流上加载 keras 模型
- android - 在 Content Provider 中定义并在 onCreate() 中初始化的全局变量在 query() 中为空
- linux - 当 DTR 和 RTS 为零时停止从 USB CDC 设备接收数据
- c - 如何分隔括号之间的术语并在C中列出它们
- java - 缺少多重继承的解决方法
- php - 让 Google 客户端在 Lumen 中工作
- python-3.x - 重新排列熊猫列中的名称顺序
- python-3.x - 在条件下删除重复
- python-3.x - Tkinter 帧没有通过类似的打包参数同等扩展