Порядок расположения элементов сетки при использовании Span - PullRequest
0 голосов
/ 02 апреля 2020

Я использую формы xamarin, и когда я использую span, я получаю странное поведение из макета сетки. Когда я хочу использовать другую строку в макете сетки, я устанавливаю свойство span равным двум. Как мне перемещать элементы слева направо, а не вниз и вверх.

enter image description here

Я бы предпочел, чтобы числа выглядели как 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>```

1 Ответ

1 голос
/ 03 апреля 2020

Если вы хотите, чтобы элементы двигались слева направо, я советую заменить CollectionView с помощью FlexLayout.

  <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>

Это снимок экрана:

enter image description here

Это статья о FlexLayout

https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/layouts/flex-layout

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...