【问题标题】:Why flutter clips children when scaling to 0.5?为什么在缩放到 0.5 时会颤动子项?
【发布时间】:2021-11-23 10:51:55
【问题描述】:

对于大于横向屏幕的小部件场景,我需要根据设备旋转应用不同的比例。

但是当我应用 0.5 比例时,孩子们被剪掉了。

如果场景在整个屏幕上可见,我应该怎么做才能缩放到 0.5?

 /// The scene: the hill, the street and the pump
  Widget scene() {
    double width = MediaQuery.of(context).size.width;
    double height = MediaQuery.of(context).size.height;

    final bool isLandscape = width > height;
    final double scale = isLandscape ? 0.5 : 1;

    return // == The custom paint sky
        Transform.scale(
            scale: scale,
            child: Stack(
              children: [
              Positioned(top: 0, width: 150, child: HillVehicleAnimation()),

【问题讨论】:

    标签: flutter widget transform scale


    【解决方案1】:

    实际上,默认情况下,Stack() 会剪辑孩子。所以添加一个clipBehavior属性并将其设置为Clip.none即可得到想要的效果如下:

    return // == The custom paint sky
            Transform.scale(
                scale: scale,
                child: Stack(
                  // == Ask Stack not to clip!
                  clipBehavior: Clip.none,
                  children: [
                  Positioned(top: 0, width: 150, child: HillVehicleAnimation()),
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-15
      • 2014-09-07
      • 2021-09-16
      • 1970-01-01
      • 2011-05-16
      • 2014-04-20
      • 2021-07-14
      • 2014-05-27
      相关资源
      最近更新 更多