我是新来的只有1天的经历 我正在尝试使用flutter开发一个Android应用程序,这是我以前的应用程序设计
我成功地制作了网格视图,但是列高是一个问题,他们的任何人都可以帮助我
我的扑动代码
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
hi(){
}
return new Scaffold(
appBar: new AppBar(
actions: <Widget>[],
title: new Text("milla"),
),
body: new Container(
child: new Center(
child: new GridView.count(
shrinkWrap: true,
scrollDirection: Axis.vertical,
childAspectRatio:1.0,
crossAxisCount: MediaQuery.of(context).size.width <= 400.0 ? 3 : MediaQuery.of(context).size.width >= 1000.0 ? 5 : 4,
// Create a grid with 2 columns. If you change the scrollDirection to
// horizontal, this would produce 2 rows.
crossAxisSpacing: 2.0,
// Generate 100 Widgets that display their index in the List
children: new List.generate(100, (index) {
return new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
verticalDirection: VerticalDirection.down,
children: <Widget>[
new Center(
child: new Image(
image: new NetworkImage('https://github.com/flutter/website/blob/master/_includes/code/layout/lakes/images/lake.jpg?raw=true')
)
),
new Expanded(child: new Text("apple2")), new Expanded(child: new Text(
'Item $index',
style: Theme.of(context).textTheme.headline,
)),new Expanded(child: new Center(child: new Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[new Text("+",style: new TextStyle(fontSize: 24.0),),new Text("1"),new Text("-")])))]
);
}),
),
),
)
);
}
}
答案 0 :(得分:1)
尝试一下
childAspectRatio: mediaQueryData.size.height / 1000,
其中
MediaQueryData mediaQueryData = MediaQuery.of(context);
我在某个地方看到了这段代码,对我来说没问题。
答案 1 :(得分:0)
放置而不是
childAspectRatio:1.0 to childAspectRatio: (itemWidth / itemHeight)
var size = MediaQuery.of(context).size.height;
final double itemHeight = (size.height) / 2;
final double itemWidth = size.width / 2;
在我的代码中可以很好地设置Gridview的高度和宽度
答案 2 :(得分:0)
您可以尝试以下方法:
GridView.count(
crossAxisCount: 2,
childAspectRatio: MediaQuery.of(context).size.height / 400,
children: <Widget>[...]
);
答案 3 :(得分:0)
维护
childAspectRatio: with MediaQuery.of(context).size.height/600
如果此Didint工作以不同但数量较少的方式更改了600。
答案 4 :(得分:0)
[屏幕截图] [https://i.stack.imgur.com/h28C2.png] 1
这是我的代码:
final screenWidth = MediaQuery.of(context).size.width/3;
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: new Container(
color: Colors.white70,
padding: EdgeInsets.all(5.0),
child: new GridView.count(
childAspectRatio: screenWidth/180.0,
crossAxisCount: 3,
crossAxisSpacing: 5.0,
mainAxisSpacing: 5.0,
children: _buildFirdTitles(35),
),
),
);