如何从头开始在xamarin表单的Flex布局中对齐项目?

时间:2018-11-11 06:25:39

标签: forms xamarin xamarin.forms

我正在使用xamarin形式V3.3.0。我从一开始就无法在Flex布局的最后一行中对齐项目。我尝试使用这些属性组合,即Direction =“ Row” Wrap =“ Wrap” JustifyContent =“ Center” AlignContent =“ Start” AlignItems =“ Start”。在下面添加了代码和图像。

<FlexLayout Direction="Row"  Wrap="Wrap" Margin="5" JustifyContent="Center"  AlignContent="Start"  AlignItems="Start">
            <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Blue" Margin="5"></BoxView>
            <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Blue" Margin="5"></BoxView>
            <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Blue" Margin="5"></BoxView>
            <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Blue" Margin="5"></BoxView>
            <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Blue" Margin="5"></BoxView>
            <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Blue" Margin="5"></BoxView>
            <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Blue" Margin="5"></BoxView>
            <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Blue" Margin="5"></BoxView>
            <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Blue" Margin="5"></BoxView>
            <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Blue" Margin="5"></BoxView>
            <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Blue" Margin="5"></BoxView>
            <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Blue" Margin="5"></BoxView>
            <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Blue" Margin="5"></BoxView>
            <BoxView HeightRequest="100" WidthRequest="100" BackgroundColor="Blue" Margin="5"></BoxView>            
        </FlexLayout>

see the image here

2 个答案:

答案 0 :(得分:0)

对于最后一行的这些项目,JustifyContent="Center"是将所有项目移到中心。

您可以改用JustifyContent="Start"

enter image description here

答案 1 :(得分:0)

您需要将flexlayout更改为此:

<FlexLayout WidthRequest="330" HorizontalOptions="Center"  Wrap="Wrap" Margin="5">

sample