美文网首页Flutter
Flutter(十)Flex弹性布局

Flutter(十)Flex弹性布局

作者: 天色将变 | 来源:发表于2019-07-17 07:36 被阅读2次

Flex与Expanded配合使用,可以按比例分配宽或高

Flex主要属性
  • direction: Axis.horizontal,// 水平方向,Expanded的height有效
  • direction: Axis.vertical,// 垂直方向,Expanded的width有效
  • children 子widget
Expanded主要属性
  • width:宽度,
  • flex:所占比例,多个Expanded之间按比例划分
  • height:高度
  • child:显示的子widget
Axis.vertical
image.png
class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Flex(
//        direction: Axis.horizontal,// 水平方向,Expanded的height有效
        direction: Axis.vertical,// 垂直方向,Expanded的width有效
        children: <Widget>[
          Expanded(
            flex: 1,
            child: Container(
              height: 20,
              width: 20,
              color: Colors.blue,
            ),
          ),
          Expanded(
            flex: 2,
            child: Container(
              height: 40,
              width: 40,
              color: Colors.green,
            ),
          ),
          Expanded(
            flex: 3,
            child: Container(
              height: 60,
              width: 60,
              color: Colors.orange,
            ),
          ),
        ],
      ),
    );
  }
}

Axis.horizontal,
image.png
class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Flex(
        direction: Axis.horizontal,// 水平方向,Expanded的height有效
//        direction: Axis.vertical,// 垂直方向,Expanded的width有效
        children: <Widget>[
          Expanded(
            flex: 1,
            child: Container(
              height: 20,
              width: 20,
              color: Colors.blue,
            ),
          ),
          Expanded(
            flex: 2,
            child: Container(
              height: 40,
              width: 40,
              color: Colors.green,
            ),
          ),
          Expanded(
            flex: 3,
            child: Container(
              height: 60,
              width: 60,
              color: Colors.orange,
            ),
          ),
        ],
      ),
    );
  }
}

相关文章

  • Flutter(十)Flex弹性布局

    Flex与Expanded配合使用,可以按比例分配宽或高 Flex主要属性 direction: Axis.hor...

  • css:About Flex

    * 弹性布局 * 创建弹性布局容器:flex containerdisplay:flex 1.弹性元素 flex ...

  • flutter基础-看完这篇就可以撸app了-有TabBar介绍

    flutter基础-看完这篇就可以撸app了 flex弹性布局学习总结 flutter layout widget...

  • flutter 弹性布局Flex

    弹性布局 弹性布局允许子widget按照一定比例来分配父容器空间,弹性布局的概念在其UI系统中也都存在,如H5中的...

  • Flutter 弹性布局 Flex

    Flex 有一个必填参数:direction,用于确定主轴的方向,然后就可以在 children 里写 子Widg...

  • 弹性布局

    弹性布局允许子组件按照一定比例来分配父容器空间。Flutter中的弹性布局主要通过Flex和Expanded来配合...

  • Flutter学习笔记12-弹性布局(Flex和Expanded

    弹性布局允许子组件按照一定比例来分配父容器空间。Flutter中的弹性布局主要通过Flex和Expanded来配合...

  • CSS3弹性布局 flexible boxes

    W3弹性布局: 弹性布局父容器(Flex Containers) 弹性布局子项(Flex Items) 子项于父容...

  • flex布局

    认识flex布局 flex布局(Flexible 布局,弹性布局)开启了flex布局的元素叫flex contai...

  • Flex布局

    Flex Flex:弹性布局 React Native 的默认布局是flex布局 如果将父元素设置成弹性盒模型模式...

网友评论

    本文标题:Flutter(十)Flex弹性布局

    本文链接:https://www.haomeiwen.com/subject/porflctx.html