Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 为什么TextAlign.left不能在小部件文本中工作?_Android_Flutter - Fatal编程技术网

Android 为什么TextAlign.left不能在小部件文本中工作?

Android 为什么TextAlign.left不能在小部件文本中工作?,android,flutter,Android,Flutter,安卓工作室3 return new Container( height: 64.0, child: new Row(children: [ new Expanded(child: new Container(color: Colors.cyanAccent, child: new Column(children: [ new Text("Today", st

安卓工作室3

  return new Container(
        height: 64.0,
        child: new Row(children: [
          new Expanded(child: new Container(color: Colors.cyanAccent,
              child: new Column(children: [
            new Text("Today",
                style: new TextStyle(
                    fontSize: 19.0,
                    color: Colors.black),
                textAlign: TextAlign.left),
            new Text("Thuersday, 26 March")
          ]))),
          new Align(alignment: Alignment.centerRight, child: new Image(image: AssetImage('assets/images/ic_profile.png')))
        ]));
正如您今天看到的对齐文本我使用
textAlign:textAlign.left
。但它不起作用

结果如下:


只有当文本占用的空间大于文本本身时,文本对齐才会起作用

将文本包装在
Align
小部件中以解决问题

return Container(
      height: 64.0,
      child: Row(
        children: [
          Expanded(
            child: Container(
              color: Colors.cyanAccent,
              child: Column(
                children: [
                  Align(
                    alignment: Alignment.centerLeft,
                    child: Text("Today",
                        style: TextStyle(fontSize: 19.0, color: Colors.black),
                        textAlign: TextAlign.left),
                  ),
                  Text("Thuersday, 26 March")
                ],
              ),
            ),
          ),
          Align(
            alignment: Alignment.centerRight,
            child: Image(
              image: AssetImage('assets/images/ic_profile.png'),
            ),
          ),
        ],
      ),
    );

有关更多信息,请参阅答案。

您必须设置文本父列的crossAxisAlignment。 该列的宽度等于其最宽的子列,默认情况下,crossAxisAlignment设置为crossAxisAlignment.center

 return Container(
        height: 64.0,
        child: Row(children: [
          Expanded(child: Container(color: Colors.cyanAccent,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
            Text("Today",
                style: new TextStyle(
                    fontSize: 19.0,
                    color: Colors.black),
                textAlign: TextAlign.left),
            Text("Thuersday, 26 March")
          ]))),
          Align(alignment: Alignment.centerRight, child: new Image(image: AssetImage('assets/images/ic_profile.png')))
        ]));

小提示->您可以避免为每个小部件键入关键字new

您希望日期也在左侧吗?@JosteveAdekanbi是的,日期也必须在左侧您认为文本占用的空间大于文本是什么意思?我对这句话感到困惑。@VirenVVarasadiya请参考我在答案中链接的上一个问题,以获得进一步解释。我检查了他们的答案,但没有得到任何想法。在那个答案中,我发现同一句话只不过如此。