gpt4 book ai didi

flutter - Flutter 中的 FractionalOffset 和 Alignment 有什么不同?

转载 作者:行者123 更新时间:2023-12-03 02:44:58 25 4
gpt4 key购买 nike

我对 FractionalOffset 和 Alignment 之间的不同感到困惑..我看到他们做同样的事情..检查我的示例代码以了解我:

示例 1:

final fractionalOffset = Container(
margin: EdgeInsets.symmetric(
vertical: 16,
),
alignment: FractionalOffset.bottomLeft,
child: Image(
image: AssetImage("example1"),
height: 92,
width: 92,
),
);

示例 2:
final alignment = Container(
margin: EdgeInsets.symmetric(
vertical: 16,
),
alignment: Alignment.bottomLeft,
child: Image(
image: AssetImage("example2"),
height: 92,
width: 92,
),
);

最佳答案

官方文档解释得很好:

FractionalOffset uses a coordinate system with an origin in the top-left corner of the rectangle whereas Alignment uses a coordinate system with an origin in the center of the rectangle.


还:

Historically, FractionalOffset predates Alignment. When we attempted to make a version of FractionalOffset that adapted to the TextDirection, we ran into difficulty because placing the origin in the top-left corner introduced a left-to-right bias that was hard to remove.


总之, FractionalOffset独立于 TextDirection ,其中 Alignment有一定的关系。
例子:

Alignment(-1.0, -1.0) represents the top left of the rectangle.

Alignment(1.0, 1.0) represents the bottom right of the rectangle.

FractionalOffset(1.0, 0.0) represents the top right of the Size.

FractionalOffset(0.0, 1.0) represents the bottom left of the Size.


下次请先查看官方文档。特别 Flutter文档组织得很好,去搜索引擎,写类名添加flutter到结束就是这样。

关于flutter - Flutter 中的 FractionalOffset 和 Alignment 有什么不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57676102/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com