xamarin形式:flex布局如何适合大于容器的内容

时间:2019-02-15 02:45:33

标签: listview xamarin layout

<FlexLayout Direction="Row" JustifyContent="Start">

                    <circle:CircleImage
                        BackgroundColor="Blue"
                        Style="{StaticResource profileStyle}"
                        Source="{Binding TeacherSource}">
                    </circle:CircleImage>

                    <FlexLayout 

                        FlexLayout.Grow="1"
                        Direction="Column" 
                        BackgroundColor="Red" 
                        JustifyContent="SpaceEvenly">

                        <Label Text="{Binding TeacherName}"    Style="{DynamicResource ListItemTextStyle}"></Label>
                        <Label Text="{Binding TeacherEmail}"   Style="{DynamicResource ListItemTextStyle}"></Label>
                        <Label Text="{Binding TeacherMobile}"  Style="{DynamicResource ListItemTextStyle}"></Label>
                        <Label Text="{Binding TeacherHome}"    Style="{DynamicResource ListItemTextStyle}"></Label>
                        <Label Text="{Binding TeacherWork}"    Style="{DynamicResource ListItemTextStyle}"></Label>

                    </FlexLayout>

                </FlexLayout>

以上xaml是在listview中使用的datatemplate内部创建的。我可以显示内容,但是最后一个标签没有扩展flexlayout以使其适合所有内容。

下图:

enter image description here

1 个答案:

答案 0 :(得分:0)

我尝试了您的代码,但没有找到让flexlayout自动扩展的解决方案。我尝试过ForceUpdateSize,但是没有运气。

如果只有一个FlexLayout,它将起作用:

<FlexLayout 
             FlexLayout.Grow="1"
             Direction="Column" 
             BackgroundColor="Red" 
             JustifyContent="SpaceEvenly">

             <Label Text="{Binding TeacherName}"    Style="{DynamicResource ListItemTextStyle}"></Label>
             <Label Text="{Binding TeacherEmail}"   Style="{DynamicResource ListItemTextStyle}"></Label>
             <Label Text="{Binding TeacherMobile}"  Style="{DynamicResource ListItemTextStyle}"></Label>
             <Label Text="{Binding TeacherHome}"    Style="{DynamicResource ListItemTextStyle}"></Label>
             <Label Text="{Binding TeacherWork}"    Style="{DynamicResource ListItemTextStyle}"></Label>    
    </FlexLayout>

我发现一个 Workaroud

将您的flexLayout更改为StackLayout即可使用:

<FlexLayout Direction="Row" JustifyContent="Start">

          <Image Source="Images"></Image>

           <StackLayout Orientation="Vertical">

                <Label Text="{Binding Name}"></Label>
                <Label Text="{Binding Image}"></Label>
                <Label Text="{Binding Image}"></Label>
                <Label Text="{Binding Image}"></Label>
                <Label Text="{Binding Image}"></Label>        
           </StackLayout>

 </FlexLayout>

请记住设置您的listView HasUnevenRows =“ True” ,不要设置rowheight

enter image description here