Horizonatal List view

Eduardo Gomez 3,416 Reputation points
2022-09-15T15:40:02.967+00:00

I am trying to do this

When the device orientation changes to landscape layout, the list should scroll horizontally, not vertically. I know that I can use a ColectionView, but I HAVE to us a list

in the specification I have

  • Using the ListView Page:
  • When the device orientation changes to landscape layout, the list should scroll horizontally, not vertically (long-press to present the user with a "do you want to delete? dialog")

I don't know how to change the orientation of a listview

I used the synfusion list, but I think, they want me to use the Xamarin List

   protected override void OnSizeAllocated(double width, double height)  
        {  
            base.OnSizeAllocated(width, height);  
  
            {  
                base.OnSizeAllocated(width, height);  
  
                if (width < height)  
                {  
                    // portrait orientation  
                }  
                else if (height < width)  
                {  
                    // landscape orientation  
                }  
            }  

     <ListView  
            x:Name="CarsList"  
            Grid.Row="1"  
            HasUnevenRows="True"  
            ItemsSource="{Binding Cars}"  
            SelectionMode="None"  
            SeparatorVisibility="Default">  
            <ListView.ItemTemplate>  
                <DataTemplate>  
                    <ViewCell>  
                        <SwipeView>  
                            <SwipeView.RightItems>  
                                <SwipeItems Mode="Execute">  
                                    <SwipeItem BackgroundColor="Red"  
                                               Command="{Binding Source={x:Reference ListPage}, Path=BindingContext.DeleteCommand}"  
                                               CommandParameter="{Binding .}"  
                                               Text="Delete" />  
                                </SwipeItems>  
                            </SwipeView.RightItems>  
                            <local:CarView  
                                Padding="0,10,0,0"  
                                xct:TouchEffect.Command="{Binding Source={x:Reference ListPage}, Path=BindingContext.PressedCommand}"  
                                xct:TouchEffect.CommandParameter="{Binding .}"  
                                xct:TouchEffect.LongPressCommand="{Binding Source={x:Reference ListPage}, Path=BindingContext.LongPressedCommand}"  
                                xct:TouchEffect.LongPressCommandParameter="{Binding .}" />  
                        </SwipeView>  
                    </ViewCell>  
                </DataTemplate>  
            </ListView.ItemTemplate>  
        </ListView>  
    </ContentPage.Content>     <ListView  
            x:Name="CarsList"  
            Grid.Row="1"  
            HasUnevenRows="True"  
            ItemsSource="{Binding Cars}"  
            SelectionMode="None"  
            SeparatorVisibility="Default">  
            <ListView.ItemTemplate>  
                <DataTemplate>  
                    <ViewCell>  
                        <SwipeView>  
                            <SwipeView.RightItems>  
                                <SwipeItems Mode="Execute">  
                                    <SwipeItem BackgroundColor="Red"  
                                               Command="{Binding Source={x:Reference ListPage}, Path=BindingContext.DeleteCommand}"  
                                               CommandParameter="{Binding .}"  
                                               Text="Delete" />  
                                </SwipeItems>  
                            </SwipeView.RightItems>  
                            <local:CarView  
                                Padding="0,10,0,0"  
                                xct:TouchEffect.Command="{Binding Source={x:Reference ListPage}, Path=BindingContext.PressedCommand}"  
                                xct:TouchEffect.CommandParameter="{Binding .}"  
                                xct:TouchEffect.LongPressCommand="{Binding Source={x:Reference ListPage}, Path=BindingContext.LongPressedCommand}"  
                                xct:TouchEffect.LongPressCommandParameter="{Binding .}" />  
                        </SwipeView>  
                    </ViewCell>  
                </DataTemplate>  
            </ListView.ItemTemplate>  
        </ListView>  
    </ContentPage.Content>v  
Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,293 questions
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 68,416 Reputation points Microsoft Vendor
    2022-09-19T01:27:38.787+00:00

    Hello,

    I spoke with the guys and I am able to use collection.

    Do you use CollectionView now?
    If so, you can set ItemsLayout="HorizontalList" to achieve Horizontal list

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful