在MaterialApp
Column
中,我在水平ListView
内有Column
。
内部 Text
是ListView(
children: [
Column(
children: [
Text('this is the text widget'),
// here I have another widget placed, just imagine a rectangle
],
],)
小部件。
textAlign: TextAlign.center,
Center
也不会使用Text
来改变Text
的位置。 import re
f = open('filename.txt', 'a').readlines()
for i in f:
value = i.rstrip()
n = re.search(r'I = (.*)', value)
i = n.group(1)
print("I = " + i)
将始终位于左上角。
另外,我在关于类似问题的答案中看到了很多关于轴对齐的内容,但我尝试了我看到的每个轴设置都没有成功。
{{3}}
如您所见,上图中的文字不居中。
答案 0 :(得分:0)
您需要crossAxisAlignment: CrossAxisAlignment.center
ListView(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('this is the text widget'),
// here I have another widget placed, just imagine a rectangle
],
),
],
)
修改强>
因为,您对上述答案不满意。我重新做了你想要的东西。请参考以下代码:
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'MediaQuery Demo',
theme: new ThemeData(
primarySwatch: Colors.red,
),
home: new MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
Widget widgetToRepeat() {
return new Column(
children: <Widget>[
new Text('Hello'),
new Container(
width: 100.0,
height: 150.0,
color: Colors.green,
margin: new EdgeInsets.all(8.0),
)
],
);
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('Demo'),
),
body: new Column(
children: <Widget>[
new Container(
child: new ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
widgetToRepeat(),
widgetToRepeat(),
widgetToRepeat(),
widgetToRepeat(),
widgetToRepeat(),
],
),
height: 150.0 + 16.0 + 20.0 + 16.0,
padding: new EdgeInsets.all(10.0),
)
],
),
);
}
}
我希望这会有所帮助。我能够在水平中心实现文本。
答案 1 :(得分:0)
return new ListView(children: [
new Center(
child: Column(
children: [
Text('this is the text widget'),
// here I have another widget placed, just imagine a rectangle
],
),
)
]);
使用新的中央窗口小部件进行扭曲