gpt4 book ai didi

flutter - 如何在 flutter 中将文本与图像对齐?

转载 作者:IT王子 更新时间:2023-10-29 07:08:13 27 4
gpt4 key购买 nike

我想将图像上的文本与左下角对齐,但即使将其与左下角对齐,它仍然停留在左上角。因此,请帮助我了解我的代码中有什么问题或缺失,以实现以下图像文本布局。

enter image description here

我的输出

enter image description here

SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: <Widget>[
Container(
width: 300,
height: 220,
alignment: Alignment.bottomLeft,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/image1.png'),
fit: BoxFit.cover),
),
child: Column(
children: <Widget>[
Text(
"Jerusalem",
style: TextStyle(
fontFamily: 'AirbnbCerealBold',
fontSize: 28,
fontWeight: FontWeight.bold,
color: Colors.white),
),
Text("1,243 Place", style: TextStyle(
fontFamily: 'AirbnbCerealBook',
fontSize: 14,
color: Colors.white),
),
],
),
),
Container(
width: 300,
height: 220,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/image3.png'),
fit: BoxFit.cover),
),
),
],
),
),

最佳答案

使用固定高度和宽度的堆栈,然后使用 Positioned/Align/any absolute positioning widgets 放置在框中的任何位置。 注意堆栈顺序是最后一个 child 第一个出现在屏幕上

Stack widget 会将 widget 放置在彼此之上,彼此之间没有响应,仅对父 Stack - 就像 CSS/HTML 中的绝对子级到相对父级

SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: <Widget>[
Container(
width: 300,
height: 220,
child: Stack(
fit: StackFit.expand,
children: <Widget>[
Image(
fit: BoxFit.cover,
image: AssetImage('assets/image1.png'),
),
Positioned(
bottom: 0,
left: 0,
child: Column(
children: <Widget>[
Text(
"Jerusalem",
style: TextStyle(
fontFamily: 'AirbnbCerealBold',
fontSize: 28,
fontWeight: FontWeight.bold,
color: Colors.white),
),
Text(
"1,243 Place",
style: TextStyle(
fontFamily: 'AirbnbCerealBook',
fontSize: 14,
color: Colors.white),
),
],
),
),
],
),
),
],
),
)

关于flutter - 如何在 flutter 中将文本与图像对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56816144/

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