微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在Flutter中在图像上叠加图标?

如何解决如何在Flutter中在图像上叠加图标?

我有一个如下所示的交错GridView。在网格的每个项目中,我都试图将图标放置在其中心,并覆盖图像的顶部。我尝试使用堆栈,但是图标似乎已移位。

这是我的代码

 class AccountViewController: UIViewController {

 @IBOutlet weak var button: UIButton!


public var accountType:String = ""
override func viewDidLoad() {
    super.viewDidLoad()
    accountType = button.currentTitle!
   
  }

,结果如下所示:

enter image description here

这就是我一直在努力实现的目标:

enter image description here

解决方法

您使用了正确的小部件Stack,但是可能您错过了一些东西。
我用ContainerStackfit: StackFit.expand,包裹了Positioned以填充所有空间,而Scaffold( body: Align( alignment: Alignment.topCenter,child: StaggeredGridView.countBuilder( crossAxisCount: 4,itemCount: 8,itemBuilder: (BuildContext context,int index) { return Stack( fit: StackFit.expand,children: [ Container( child: ClipRRect( borderRadius: BorderRadius.all(Radius.circular(6)),child: Image.network( 'https://images.unsplash.com/photo-1534361960057-19889db9621e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60',fit: BoxFit.fitHeight,),Positioned(child: Icon(Icons.play_arrow)) ],); },staggeredTileBuilder: (int index) => new StaggeredTile.count(2,index.isEven ? 2 : 3),mainAxisSpacing: 4.0,crossAxisSpacing: 4.0,) 将在中间 因此,这里有完整的代码,它可能会有所帮助:

<select class="form-control" name="role" id="role" formControlName="role">
     <option value="" disabled selected>Select the role</option>
     <option *ngFor="let role of roleList" value="{{ role }}">{{role}}</option>
</select>
,

使用Stack窗口小部件的对齐属性为center。

child: Stack(
  alignment: Alignment.center,children: <Widget>[
     //Image
     //Icon
  ],

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?