0

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

I cannot find anything related to making a horizontal listview, and I don't think is possible

edu
  • 87
  • 2
  • 8
  • 1
    Why can't you use a CollectionView Exactly? – FreakyAli Sep 16 '22 at 05:15
  • 1
    You may have 2 folders for layouts and one should be called. You may also name your layouts the same. For more details, please refer to the link:"https://stackoverflow.com/questions/40091447/android-change-listview-item-layout-when-changing-orientation". – Hongxin Sui-MSFT Sep 16 '22 at 08:32
  • 1
    ListView doesn’t have an orientation. It’s always vertical – Jason Sep 16 '22 at 10:37
  • @Jason I found this https://github.com/pictos/HorizontalList/blob/master/App3/App3/MainPage.xaml and I already have the code, to detect orientation ` 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 //} } – edu Sep 16 '22 at 14:29

0 Answers0