加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Flutter基础—布局模型之水平垂直

发布时间:2020-12-14 14:54:53 所属栏目:百科 来源:网络整理
导读:水平布局 Row控件即水平布局控件,能够将子控件水平排列。 Row子控件有灵活与不灵活的两种,Row首先列出不灵活的子控件,减去它们的总宽度,计算还有多少可用的空间。然后Row按照Flexible.flex属性确定的比例在可用空间中列出灵活的子控件。要控制灵活子控件

水平布局

Row控件即水平布局控件,能够将子控件水平排列。

Row子控件有灵活与不灵活的两种,Row首先列出不灵活的子控件,减去它们的总宽度,计算还有多少可用的空间。然后Row按照Flexible.flex属性确定的比例在可用空间中列出灵活的子控件。要控制灵活子控件,需要使用Flexible控件:

import 'package:flutter/material.dart';
class LayoutDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('水平方向布局'),),body: new Row(
        children: <Widget>[
          new RaisedButton(
            onPressed: () {
              print('点击红色按钮事件');
            },color: const Color(0xffcc0000),child: new Text('红色按钮'),new Flexible(
            flex: 1,child: new RaisedButton(
              onPressed: () {
                print('点击黄色按钮事件');
              },color: const Color(0xfff1c232),child: new Text('黄色按钮'),new RaisedButton(
            onPressed: () {
              print('点击粉色按钮事件');
            },color: const Color(0xffea9999),child: new Text('粉色按钮'),]
      ),);
  }
}
void main() {
  runApp(
    new MaterialApp(
      title: 'Flutter教程',home: new LayoutDemo(),);
}

垂直布局

Column控件即垂直布局控件,能够将子控件垂直排列。

与Row控件一样,Column控件的子控件也有分灵活与不灵活的。首先Column列出不灵活的子控件,减去它们的总高度,计算还有多少可用空间。然后Column按照Flexible.flex属性确定的比例在可用空间中列出灵活的子控件。要控制灵活子控件,需要使用Flexible控件:

import 'package:flutter/material.dart';
class LayoutDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('垂直方向布局'),body: new Column(
        children: <Widget>[
          new RaisedButton(
            onPressed: () {
              print('点击红色按钮事件');
            },);
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读