Tom*_*myF 30 flutter flutter-layout
我在Flutter的布局方面仍然遇到一些麻烦.
现在我希望在象限布局中在3个小部件之间共享可用空间.宽度均匀分享(这可以通过Expanded一行中的两个小部件正常工作),但现在我也希望高度自动调整widget3.height == widget1.height + widget2.height.
如果内容widget3较大,我想要widget1并widget2调整它们的高度,反之亦然.
这在Flutter中甚至可能吗?
Mat*_* S. 84
看看IntrinsicHeight; 包装根行应该提供您正在寻找的效果:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(title: Text('Rows & Columns')),
body: RowsAndColumns(),
),
);
}
}
class RowsAndColumns extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(top: 100.0),
child: IntrinsicHeight(
child: Row(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
Expanded(
child: Column(children: [
Container(height: 120.0, color: Colors.yellow),
Container(height: 100.0, color: Colors.cyan),
]),
),
Expanded(child: Container(color: Colors.amber)),
]),
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
调整列中容器的高度会导致右侧的容器调整大小以匹配:
https://gist.github.com/mjohnsullivan/c5b661d7b3b4ca00599e8ef87ff6ac61
obl*_*mov 11
由于IntrinsicHeight被认为相对昂贵,所以最好避免它。您可以Table与VerticalAlignment 一起使用:TableCellVerticalAlignment.fill中最大的TableCell。
请注意,如果您.fill在所有单元格中使用,则高度TableRow将为零。
Table(children: [
TableRow(children: [
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
alignment: Alignment.center,
color: Colors.blue,
child: Text('Widget 1'),
),
Container(
alignment: Alignment.center,
color: Colors.green,
child: Text('Widget 2'),
),
],
),
TableCell(
verticalAlignment: TableCellVerticalAlignment.fill,
child: Container(
alignment: Alignment.center,
color: Colors.orange,
child: Text('Widget 3'),
)),
]),
]),
Run Code Online (Sandbox Code Playgroud)
Dan*_*cia 10
我认为你可以设置行的高度,然后你只需要设置列容器的高度,并且使用crossAxisAlignment: CrossAxisAlignment.stretch第二行将扩展占据他的父高度:
Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: Column(
children: [
Expanded(
// If you don't have the height you can expanded with flex
flex: 1,
child: Container(
height: 50,
color: Colors.blue,
),
),
Expanded(
flex: 1,
child: Container(
height: 50,
color: Colors.red,
),
)
],
),
),
Expanded(
child: Container(
color: Colors.yellow,
),
)
],
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
29880 次 |
| 最近记录: |