颤振如何将项目移动到底部 我有这两个项目,一个需要出现在中间,另一个需要移到底部。 import 'package:flutter/material.dart'; class WelcomeScreen extends StatelessWidget { @override Widget build(BuildContext context) { return Container( color: Colors.blue, child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Text( 'K', style: TextStyle( fontSize: 200, color: Colors.white, decoration: TextDecoration.none, fontStyle: FontStyle.italic, ), ), Column( mainAxisAlignment: MainAxisAlignment.end, children: [Text('hello')], ) ], ), ); } }

颤振如何将项目移动到底部 我有这两个项目,一个需要出现在中间,另一个需要移到底部。 import 'package:flutter/material.dart'; class WelcomeScreen extends StatelessWidget { @override Widget build(BuildContext context) { return Container( color: Colors.blue, child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Text( 'K', style: TextStyle( fontSize: 200, color: Colors.white, decoration: TextDecoration.none, fontStyle: FontStyle.italic, ), ), Column( mainAxisAlignment: MainAxisAlignment.end, children: [Text('hello')], ) ], ), ); } },flutter,Flutter,这就是它的样子 我想将Hello文本移到底部。我该怎么做呢?如果你不想让你的K文本在上面移动,你必须使用堆栈。这样,你的小部件可以在任何他们想要的地方定位 Stack( alignment:Alignment.center, children:[ Text("K"), Align( alignment:Alignment.bottomCenter, child:Text("hello"), ), ] ), 在这里查看stack小部件: 这样怎么样?添加

这就是它的样子


我想将Hello文本移到底部。我该怎么做呢?

如果你不想让你的K文本在上面移动,你必须使用堆栈。这样,你的小部件可以在任何他们想要的地方定位

Stack(
alignment:Alignment.center,
children:[
Text("K"),
Align(
alignment:Alignment.bottomCenter,
child:Text("hello"),
),
]
),
在这里查看stack小部件:


这样怎么样?添加两个垫片

为此,您需要使用两种方法,以使其更有效地工作。这些是:

  • ->这将提供空间,即占用剩余空间
  • ->这将帮助您对齐项目
请注意:
Align()
本身无法对齐项目,除非给出空格。如果只使用
Align()
,则不会看到任何更改,因为
Text('Hello')
查找空格,但没有空格

代码

      Container(
       width: double.infinity,  // <-- Takes up total width of the device
       height: double.infinity, // <-- Takes up the total height of the device
       color: Colors.blue,
       child: Column(
        children: [
          Expanded(
            flex: 2, // <-- Flex takes care of the remaining space ratio
            child: Center(
              child: Text(
                'K',
                style: TextStyle(
                  fontSize: 200,
                  color: Colors.white,
                  decoration: TextDecoration.none,
                  fontStyle: FontStyle.italic,
                ),
              )
            )
          ),
          Align(
            alignment: Alignment.bottomCenter,
            child: Text('Hello', style: TextStyle(color: Colors.white, fontSize: 17.0))
          )
        ]
      )
     )
容器(

宽度:double.infinity,//是的,我刚从react背景开始。我还可以在对齐小部件的底部放置按钮吗?是的。只要小部件周围有可移动的空间,对齐就可以将小部件对齐到任意位置。另一方面,间隔符占据了最大的空间,使其下方的文本成为可能转到屏幕最底部。非解决方案工作。对齐不会将文本移动到底部我猜是空间不可用。间隔符将K移动到顶部,文本移动到底部。扩展的小部件将我的K移动到顶部,将Hello移动到底部。我更新了我的答案。我忘了你还有文本K。嘿@user3862830我已经给出了另一个答案。请检查:)间隔符没有准确地将k文本居中,虽然这是一个好答案,但如果他的hello文本的大小更大呢?它会把K向上推。K不再居中。这是真的,因此可以使用@Uni。如果你想要那个答案,让我知道:)你可以保留它。这也是一篇好文章,因为这篇文章很小。最好让OP知道这一点的局限性。我是为你问的,如果你还在考虑如何实现你的目标的话。我可以添加答案,然后你可以标记这个答案,这样人们就会知道不同的方法@统一
      Container(
       width: double.infinity,  // <-- Takes up total width of the device
       height: double.infinity, // <-- Takes up the total height of the device
       color: Colors.blue,
       child: Column(
        children: [
          Expanded(
            flex: 2, // <-- Flex takes care of the remaining space ratio
            child: Center(
              child: Text(
                'K',
                style: TextStyle(
                  fontSize: 200,
                  color: Colors.white,
                  decoration: TextDecoration.none,
                  fontStyle: FontStyle.italic,
                ),
              )
            )
          ),
          Align(
            alignment: Alignment.bottomCenter,
            child: Text('Hello', style: TextStyle(color: Colors.white, fontSize: 17.0))
          )
        ]
      )
     )