0

I modify the sample https://learn.microsoft.com/zh-tw/samples/xamarin/xamarin-forms-samples/userinterface-xaminals/ ,

replace the collectionview with listview . after replacing I found the listview cannot scroll to bottom (there are total 17 items , but only show 6 items)

This error only happen on Android,but it works well on IOS.

How to solve this problem?

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
             xmlns:controls="clr-namespace:Xaminals.Controls"
             xmlns:data="clr-namespace:Xaminals.Data"
             x:Class="Xaminals.Views.MonkeysPage"
             Title="Monkeys">
     <RelativeLayout
                VerticalOptions="FillAndExpand"
                HorizontalOptions="FillAndExpand">

   
        <StackLayout Orientation="Vertical"
                               VerticalOptions="FillAndExpand"
                               Padding="10">


            <ListView     ItemsSource="{x:Static data:MonkeyData.Monkeys}"
                            x:Name="CollectionView1"  
                           
                            RowHeight="100">

                <ListView.ItemTemplate>
                    <DataTemplate>

                         <ViewCell>
                 
                            <Grid VerticalOptions="CenterAndExpand" Padding = "20, 0" >
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>

                                <Image
                                      Grid.RowSpan="2"
                                      Aspect="AspectFill"
                                      HeightRequest="60"
                                      Source="{Binding ImageUrl}"
                                      WidthRequest="60" />

                                <Label
                                      Grid.Row="0"
                                      Grid.Column="1"
                                      FontAttributes="Bold"
                                      Text="{Binding Name}" />

                                <Label
                                      Grid.Row="1"
                                      Grid.Column="1"
                                      FontAttributes="Italic"
                                      Text="{Binding Price}"
                                      VerticalOptions="End" />

                                <Image Grid.Row="2" Grid.Column="0"  Source="bear.png" HeightRequest="25" WidthRequest="25">
                                    <Image.GestureRecognizers>
                                        <TapGestureRecognizer
                                             
                                             NumberOfTapsRequired="1" />
                                    </Image.GestureRecognizers>
                                </Image>
                            </Grid>
                  
                           </ViewCell> 

                    </DataTemplate>

                </ListView.ItemTemplate>

            </ListView>


        </StackLayout>

          <ActivityIndicator x:Name="activityIndicator" Color="Red"  VerticalOptions="CenterAndExpand"  HorizontalOptions="CenterAndExpand"  RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.33}" RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height,Factor=0.33}"    />

    </RelativeLayout>

</ContentPage>

1 Answer 1

1

The solution is change the RelativeLayout to Stacklayout:

<StackLayout
            VerticalOptions="FillAndExpand"
            HorizontalOptions="FillAndExpand">


    <StackLayout Orientation="Vertical"
                           VerticalOptions="FillAndExpand"
                           Padding="10">

        <ListView     ItemsSource="{x:Static data:MonkeyData.Monkeys}"
                        x:Name="CollectionView1"  
                        RowHeight="100">

            .....
        </ListView>

    </StackLayout>
</StackLayout>

If you want to use RelativeLayout, you need to use XConstraint, YConstraint,WidthConstraint,HeightConstraint to layout the child view instead of VerticalOptions="FillAndExpand", HorizontalOptions="FillAndExpand".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.