我是一名Android开发人员,不熟悉。
我想创建一个高度为GridView
的{{1}}(我在屏幕截图中用笔绘制)。但是我尝试了以下代码,它只给了我方格项目。我想如何获取高度包裹内容网格项目,我不知道,也找不到如何获取它。请帮忙。谢谢。
wrap content
答案 0 :(得分:2)
对于高度,您可以使用“ childAspectRatio”
例如-
GridView.count(
childAspectRatio: 4.0,
crossAxisCount: 2,
padding: EdgeInsets.all(5.0),
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 10.0, right: 10.0, top: 5.0),
child: Text(
'10:00 AM - 12:00 PM',
style: new TextStyle( color: Colors.black87, fontSize: 14.0,
fontWeight: FontWeight.normal,
),
),
);
],
shrinkWrap: true,
// todo comment this out and check the result
physics: ClampingScrollPhysics(),
)
答案 1 :(得分:0)
要包装内容网格项目,可以使用gridview的 childAspectRatio 属性
例如。
GridView.builder(
itemCount: widget.items.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: (orientation == Orientation.portrait) ? 2 : 3, childAspectRatio:(MediaQuery.of(context).size.height * 0.006)),
itemBuilder: (BuildContext context, int index) {
return CategoryItem(category: widget.items[index],);
},
)
您可以设置childAspectRatio
0.006
而不是根据您的内容大小
答案 2 :(得分:0)
您需要设置childAspectRatio
委托的SliverGridDelegateWithFixedCrossAxisCount
属性,以控制相对于网格项目宽度的高度。
如果您只是想“缩小”文本窗口小部件的高度(类似match_parent
的高度),请将其环绕在Column
,Row
和Expanded
周围像这样
class CategoryItem extends StatelessWidget {
final Category category;
CategoryItem({Key key, @required this.category})
: assert(category != null),
super(key: key);
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Row(
children: <Widget>[
Expanded(
child: Card(
child: Text(
category.name,
style: TextStyle(fontSize: 34.0, fontWeight: FontWeight.bold),
),
color: Colors.amberAccent,
),
),
],
),
],
);
}
}
答案 3 :(得分:0)
在GridView中使用此行
SERIAL_NO|N|1385,45,871,104|1|?
CUST_ID|N|1704,211,552,71|1|?
PROD_TYPE|A|367,286,1167,74|1|?
BRANCH_CODE|N|1892,429,254,74|1|?
CONSTITUION|C|279,1355,85,62-539,1355,75,59-757,1352,72,62-884,1352,52,55-998,1352,68,55-1310,1352,68,49-1596,1349,65,55-1762,1352,68,49-1905,1352,69,52-2113,1352,62,49-78,1423,61,49-282,1410,78,65-432,1417,68,58-656,1417,78,55-969,1414,71,61-1222,1414,72,55-1391,1414,78,55|1|Sole proprietor?Partnership?LLP?HUF?Private Ltd Company?Public Ltd Company?Society?Trust?NGO/NPO?SHG?Association?Club?University?Government Body?Financial Inst?Bank?JLG?
ACTIVITY|C|221,1498,71,52-400,1498,71,52-552,1495,59,45-702,1498,65,49-881,1495,62,49-1043,1495,69,52-1252,1495,58,42-1473,1495,75,49-1671,1495,65,52-1935,1485,74,59-224,1563,65,49-734,1553,59,52-1056,1557,62,45|1|Agri?Mfg?Trade?Finance?Bank?Transport?Services?Govt?Real Estate?Stock Broker?Jewels/Gems/Precious Metal dealer?Money Services?Others (specify)?
NAME_AUTH_SIG1|A|97,1713,1327,65|1|?