问题描述
有人可以帮助我将“轮廓”按钮水平居中吗? Crossalignmentaxis.center似乎不起作用。
Container(
child: Center(
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,children: <Widget>[
OutlineButton(
child: Text(
'Hours',textAlign: TextAlign.center,style: TextStyle(
fontSize: 45.0,color: Colors.white,fontFamily: 'HousePlant2'),),borderSide: BorderSide(
color: Colors.white,style: BorderStyle.solid,width: 2),shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(20)),onpressed: () {},],)
解决方法
您需要为mainAxisAlignment: MainAxisAlignment.center
设置Row
,因为行的主轴是水平轴,行的交叉轴是垂直轴。
Container(
// color: Colors.red,child: Center(
child: Row(mainAxisAlignment:MainAxisAlignment.center,crossAxisAlignment: CrossAxisAlignment.center,children: <Widget>[
OutlineButton(
child: Text(
'Hours',textAlign: TextAlign.center,style: TextStyle(
fontSize: 45.0,color: Colors.white,fontFamily: 'HousePlant2'),),borderSide: BorderSide(
color: Colors.white,style: BorderStyle.solid,width: 2),shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(20)),onPressed: () {},],