Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin 使用Span时的网格布局项顺序_Xamarin_Xamarin.forms - Fatal编程技术网

Xamarin 使用Span时的网格布局项顺序

Xamarin 使用Span时的网格布局项顺序,xamarin,xamarin.forms,Xamarin,Xamarin.forms,我使用的是xamarin表单,当我使用span时,我从网格布局中得到了奇怪的行为。当我想在网格布局中使用另一行时,我将span属性设置为2。如何保持项目从左向右移动,而不是上下移动 我宁愿数字看起来像这样 01 02 03 04 下面是所有的代码 <ListView x:Name="ItemsListView" ItemsSource="{Binding Items}" VerticalOptions="F

我使用的是xamarin表单,当我使用span时,我从网格布局中得到了奇怪的行为。当我想在网格布局中使用另一行时,我将span属性设置为2。如何保持项目从左向右移动,而不是上下移动

我宁愿数字看起来像这样 01 02 03 04
下面是所有的代码

        <ListView x:Name="ItemsListView"
                ItemsSource="{Binding Items}"
                VerticalOptions="FillAndExpand"
                HasUnevenRows="true"
                RefreshCommand="{Binding LoadItemsCommand}"
                IsPullToRefreshEnabled="true"
                IsRefreshing="{Binding IsBusy, Mode=OneWay}"
                CachingStrategy="RecycleElement"
                ItemSelected="OnItemSelected">
            <d:ListView.ItemsSource>
                <x:Array Type="{x:Type x:String}">
                    <x:String>First Item</x:String>
                    <x:String>Second Item</x:String>
                    <x:String>Third Item</x:String>
                    <x:String>Forth Item</x:String>
                    <x:String>Fifth Item</x:String>
                    <x:String>Sixth Item</x:String>
                </x:Array>
            </d:ListView.ItemsSource>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout Padding="1,10,10,10">
                            <Label Text="{Binding name}" 
                                d:Text="{Binding .}"
                                LineBreakMode="NoWrap" 
                                Style="{DynamicResource ListItemTextStyle}" 
                                FontSize="16" />
                            <Frame BorderColor="Blue" >
                            <RelativeLayout HorizontalOptions="Start" VerticalOptions="Fill" HeightRequest="40"   >
                                <CollectionView ItemsSource="{Binding balls}"
                                                HorizontalOptions="StartAndExpand"
                                                >
                                    <CollectionView.ItemsLayout>
                                        <GridItemsLayout Orientation="Horizontal" Span="2"/>
                                    </CollectionView.ItemsLayout>
                                        <d:CollectionView.ItemsSource>
                                        <x:Array Type="{x:Type x:String}">
                                            <x:String>01</x:String>
                                            <x:String>02</x:String>
                                            <x:String>03</x:String>
                                            <x:String>04</x:String>
                                            <x:String>05</x:String>
                                            <x:String>06</x:String>
                                            <x:String>07</x:String>
                                            <x:String>08</x:String>
                                            <x:String>09</x:String>
                                            <x:String>10</x:String>
                                            <x:String>11</x:String>
                                            <x:String>12</x:String>
                                            <x:String>13</x:String>
                                            <x:String>14</x:String>
                                            </x:Array>
                                    </d:CollectionView.ItemsSource>
                                    <CollectionView.ItemTemplate>
                                        <DataTemplate>
                                            <Grid>
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="Auto"/>
                                                        <ColumnDefinition Width="1" />
                                                    </Grid.ColumnDefinitions>
                                                    <Grid.RowDefinitions>
                                                        <RowDefinition Height="40"/>
                                                    </Grid.RowDefinitions>
                                                    <AbsoluteLayout Grid.Column="0">
                                                        <Label Text="{Binding number}" 
                                                               d:Text="{Binding .}"
                                                               Style="{DynamicResource ListItemDetailTextStyle}" 
                                                               FontSize="16"  />
                                                    </AbsoluteLayout>
                                                </Grid>

                                            </DataTemplate>
                                    </CollectionView.ItemTemplate>
                                </CollectionView>
                                </RelativeLayout>
                                </Frame>                              
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout>```

第一项
第二项
第三项
第四项
第五项
第六项
01
02
03
04
05
06
07
08
09
10
11
12
13
14
```

如果您想保持项目从左向右移动,我建议您可以使用FlexLayout替换CollectionView

  <ListView
            x:Name="ItemsListView"
            CachingStrategy="RecycleElement"
            HasUnevenRows="true"
            VerticalOptions="FillAndExpand">
            <ListView.ItemsSource>
                <x:Array Type="{x:Type x:String}">
                    <x:String>First Item</x:String>
                    <x:String>Second Item</x:String>
                    <x:String>Third Item</x:String>
                    <x:String>Forth Item</x:String>
                    <x:String>Fifth Item</x:String>
                    <x:String>Sixth Item</x:String>
                </x:Array>
            </ListView.ItemsSource>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout Padding="1,10,10,10">
                            <Label
                                FontSize="16"
                                LineBreakMode="NoWrap"
                                Text="{Binding .}" />

                            <Frame BorderColor="Blue">
                                <StackLayout HorizontalOptions="Start" VerticalOptions="FillAndExpand">
                                    <FlexLayout
                                        AlignContent="Start"
                                        AlignItems="Start"
                                        Direction="Row"
                                        JustifyContent="SpaceAround"
                                        Wrap="Wrap">

                                        <BindableLayout.ItemsSource>
                                            <x:Array Type="{x:Type x:String}">
                                                <x:String>01</x:String>
                                                <x:String>02</x:String>
                                                <x:String>03</x:String>
                                                <x:String>04</x:String>
                                                <x:String>05</x:String>
                                                <x:String>06</x:String>
                                                <x:String>07</x:String>
                                                <x:String>08</x:String>
                                                <x:String>09</x:String>
                                                <x:String>10</x:String>
                                                <x:String>11</x:String>
                                                <x:String>12</x:String>
                                                <x:String>13</x:String>
                                                <x:String>14</x:String>

                                            </x:Array>
                                        </BindableLayout.ItemsSource>
                                        <BindableLayout.ItemTemplate>
                                            <DataTemplate>
                                                <StackLayout>
                                                    <Label
                                                        Padding="14"
                                                        FontSize="16"
                                                        Text="{Binding .}" />
                                                </StackLayout>
                                            </DataTemplate>
                                        </BindableLayout.ItemTemplate>
                                    </FlexLayout>

                                </StackLayout>
                            </Frame>

                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

第一项
第二项
第三项
第四项
第五项
第六项
01
02
03
04
05
06
07
08
09
10
11
12
13
14
这是屏幕截图:

这是一篇关于FlexLayout的文章