MainAxisAlignment
MainAxisAlignment
枚举具有以下值:
START
: 子项从容器的起始位置开始排列。END
: 子项从容器的结束位置开始排列。CENTER
: 子项在容器中居中排列。SPACE_BETWEEN
: 子项在容器中平均分布,第一个子项放置在起始位置,最后一个子项放置在结束位置,其余子项均匀分布。SPACE_AROUND
: 子项在容器中平均分布,每个子项周围有相等的间距。SPACE_EVENLY
: 子项在容器中平均分布,每个子项之间和容器边缘之间的间距相等。
使用示例
- Python
import flet as ft
def main(page: ft.Page):
def items(count):
items = []
for i in range(1, count + 1):
items.append(
ft.Container(
content=ft.Text(value=str(i)),
alignment=ft.alignment.center,
width=50,
height=50,
bgcolor=ft.colors.AMBER_500,
)
)
return items
def column_with_alignment(align: ft.MainAxisAlignment):
return ft.Column(
[
ft.Text(str(align), size=10),
ft.Container(
content=ft.Column(items(3), alignment=align),
bgcolor=ft.colors.AMBER_100,
height=400,
),
]
)
page.add(
ft.Row(
[
column_with_alignment(ft.MainAxisAlignment.START),
column_with_alignment(ft.MainAxisAlignment.CENTER),
column_with_alignment(ft.MainAxisAlignment.END),
column_with_alignment(ft.MainAxisAlignment.SPACE_BETWEEN),
column_with_alignment(ft.MainAxisAlignment.SPACE_AROUND),
column_with_alignment(ft.MainAxisAlignment.SPACE_EVENLY),
],
spacing=30,
alignment=ft.MainAxisAlignment.START,
)
)
ft.app(target=main)