7. Flutter——GridView元件
GridView 元件的常用引數
-
當資料量很大的時候用矩陣方式排列比較清晰。此時我們可以用網格列表元件 GridView 實 現佈局。
-
常用屬性:
名稱 | 型別 | 說明 |
---|---|---|
scrollDirection | Axis | 滾動 |
padding | EdgeInsetsGeometry | 內邊距 |
resolve | bool | 元件反向序列化 |
crossAxisSpacing | double | 水平子 Widget 之間間距 |
mainAxisSpacing | double | 垂直子 Widget 之間間距 |
crossAxisCount | int | 一行的 Widget 數量 |
childAspectRatio | double | 子 Widget 寬高比例 |
children | int | < Widget >[ ] |
gridDelegate | SliverGridDelegateWithFix edCrossAxisCount(常用) SliverGridDelegateWithMax CrossAxisExtent | 控制佈局主要用在 GridView.builder 裡面 |
GridView.count 實現網格佈局
import'package:flutter/material.dart';
import'res/listData.dart';
voidmain()=>runApp(MyApp());
classMyAppextendsStatelessWidget{
@override
Widgetbuild(BuildContextcontext){
returnMaterialApp(
home:Scaffold(
appBar:AppBar(title:Text('FlutterDemo')),
body:LayoutContent(),
));
}
}
classLayoutContentextendsStatelessWidget{
List<Widget>_getListData(){
vartempList=listData.map((value){
returnContainer(
child: Column(
children:<Widget>[
Image.network(value["imageUrl"]),
SizedBox(height:12),
Text(value["title"],
textAlign:TextAlign.center,
style:TextStyle(fontSize:20)),
],
),
decoration:BoxDecoration(
border:Border.all(
color:Color.fromRGBO(230,230,230,0.9),
width:1.0
)
),
);
});
returntempList.toList();
}
@override
Widgetbuild(BuildContextcontext){
returnGridView.count(
padding:EdgeInsets.all(20),
crossAxisCount:2,
crossAxisSpacing:20,
mainAxisSpacing:20,
children:this._getListData(),
);
}
}
GridView.builder 實現網格佈局
import'package:flutter/material.dart';
import'res/listData.dart';
voidmain()=>runApp(MyApp());
classMyAppextendsStatelessWidget{
@override Widgetbuild(BuildContextcontext){
returnMaterialApp(
home:Scaffold(
appBar:AppBar(title:Text('FlutterDemo')),
body:LayoutContent(),
));
}
}
classLayoutContentextendsStatelessWidget{
Widget_getListData(context,index){
returnContainer(
child: Column(
children:<Widget>[
Image.network(listData[index]["imageUrl"]),
SizedBox(height:12),
Text(listData[index]["title"],
textAlign: TextAlign.center,style:TextStyle(fontSize: 20)),
],
),
decoration:BoxDecoration(
border:Border.all(
color:Color.fromRGBO(230,230,230,0.9),
width:1.0
)
),
);
}
@override
Widgetbuild(BuildContextcontext){
returnGridView.builder(
itemCount:listData.length,
gridDelegate:SliverGridDelegateWithFixedCrossAxisCount(
//橫軸元素個數
crossAxisCount:2,
//縱軸間距
mainAxisSpacing:20.0,
//橫軸間距
crossAxisSpacing:10.0,
//子元件寬高長度比例
childAspectRatio:1.0
),
itemBuilder:this._getListData,
);
}
}
相關文章
- flutter Swiper+GridViewFlutterView
- jQuery找到GridView控制元件jQueryView控制元件
- Flutter的staggered GridView詳細使用FlutterView
- Flutter網格型佈局 - GridView篇FlutterView
- Flutter元件Flutter元件
- Flutter 佈局(八)- Stack、IndexedStack、GridView詳解FlutterIndexView
- [Android] 列表控制元件(RecycleView,GridView)Android控制元件View
- .NET基礎之GridView控制元件View控制元件
- Flutter入門進階之旅(十四)ListView&GridViewFlutterView
- Flutter元件ImageFlutter元件
- Flutter Web網站之ScrollView+GridView優化FlutterWeb網站View優化
- Flutter GridView 中使用Offstage 或者 Visibility 無效FlutterView
- Flutter元件學習(一)—— Text元件Flutter元件
- Flutter元件大全(一)Flutter元件
- Flutter元件大全(四)Flutter元件
- Flutter元件大全(五)Flutter元件
- Flutter 元件總結Flutter元件
- Flutter元件總結Flutter元件
- Flutter | 佈局元件Flutter元件
- Flutter動畫 5 - Flutter內建動畫元件Flutter動畫元件
- GridView修改含有DropDownList控制元件列的寬度View控制元件
- 7.介面
- Flutter 拖拽排序元件 ReorderableListViewFlutter排序元件View
- Flutter元件之ChoiceChip教程Flutter元件
- Flutter自定義元件-MultiShowerFlutter元件
- Unity的Flutter元件渲染UnityFlutter元件
- Android UI控制元件系列:GridView(網格佈局)AndroidUI控制元件View
- Flutter基礎(七)Scrolling Widget之ListView、GridView、PageViewFlutterView
- Flutter 基礎(七)Scrolling Widget 之 ListView、GridView、PageViewFlutterView
- Flutter新手入門常用元件總結,讓你瞭解更多的Flutter元件?Flutter元件
- GridViewView
- Flutter元件化探索——Pod整合Flutter元件化
- 響應式 Echarts Flutter 元件EchartsFlutter元件
- Flutter——Materia Design元件集合Flutter元件
- Flutter 的基本控制元件Flutter控制元件
- Flutter | 1.9 全新元件 ToggleButtonsFlutter元件
- Flutter 開發之元件一Flutter元件
- Flutter元件學習(二)—— ImageFlutter元件