question

SSB-7585 avatar image
0 Votes"
SSB-7585 asked LeonLu-MSFT answered

Xamarin Forms Android Scoll / Load More not working

Hi,

I have a StackLyout within a ScrollView within an Absolute Layout.

When i scroll to the end of the scrollview, i need to call a LoadMore method - the code I have is below - this all works perfectly fine on iPhone, however on Android it doesn't detect the end of scrollview for some reason - any ideas what is missing or needs to be adjusted for android?



 private int i = 0;
 async void ScrollView_Scrolled(System.Object sender, Xamarin.Forms.ScrolledEventArgs e)
         {
             if (!(sender is ScrollView scrollView))
                 return;
    
             var scrollingSpace = scrollView.ContentSize.Height - scrollView.Height;
    
             if (scrollingSpace > e.ScrollY)
                 return; // ----> This is always being hit on Android even at the end of the scrollview. Works in iOS
    
    
    
             // load more content.
             if (i == 0)
             {
    
     
                 await scrollView.ScrollToAsync(e.ScrollX, e.ScrollY - 100, true);
                 i = 1;
                 //await DisplayAlert("Alert", "End of scroll view detected", "OK");
    
                 if(_vm.CurrentPage < _vm.TotalPages)
                 {
                    _vm.CurrentPage = _vm.CurrentPage + 1;
                     await _vm.LoadData();
                }
                    
                 i = 0;
    
             }
    
    
         }




Layout:

     <AbsoluteLayout>
         <StackLayout    AbsoluteLayout.LayoutBounds="0,0,1,1"
                     AbsoluteLayout.LayoutFlags="All">

             <Label Text="Adjust preferences" FontFamily="Poppins-Bold" TextColor="#595959" FontSize="12" HorizontalTextAlignment="Center" Margin="0,10">
                 <Label.GestureRecognizers>
                     <TapGestureRecognizer Tapped="btn_Filter_Clicked"/>
                 </Label.GestureRecognizers>

             </Label>

     <ScrollView
         Scrolled="ScrollView_Scrolled"
         Padding="0,10,0,0">

         <StackLayout>
         <StackLayout
             BindableLayout.ItemsSource="{Binding SearchResults}"
             >

             <BindableLayout.ItemTemplate>
                 <DataTemplate>

                     <customView:MyView MyContent="{Binding }" />
   

                 </DataTemplate>

             </BindableLayout.ItemTemplate>

        </StackLayout>


             <StackLayout>
                 <Label Text="Load More" HorizontalOptions="Center" FontFamily="Poppins-Regular"
                        FontSize="14" TextColor="#707070"/>
             </StackLayout>


         </StackLayout>



 </ScrollView>
 </StackLayout>


     <yummy:PancakeView x:Name="view_Incognito" CornerRadius="10"
             AbsoluteLayout.LayoutBounds="0.5,0.09"
             AbsoluteLayout.LayoutFlags="PositionProportional"
             BackgroundColor="Red"
             IsVisible="{Binding IncognitoEnabled, Mode=TwoWay, FallbackValue=False}"      
             Padding="35,5"
                      >

   </yummy:PancakeView>


    <loadViews:LoadingFullScreenView
        AbsoluteLayout.LayoutBounds="0,0,1,1"
                     AbsoluteLayout.LayoutFlags="All"
                     IsVisible="{Binding Loading}                       
       />



 </AbsoluteLayout>




dotnet-xamarinformsdotnet-android
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

LeonLu-MSFT avatar image
0 Votes"
LeonLu-MSFT answered

Hello,​

Welcome to our Microsoft Q&A platform!

This issue is related to your Padding="0,10,0,0" in the <ScrollView>.

If I delete it. It worked in my android device.

Here is running screenshot.



82301-image.png

Best Regards,

Leon Lu



If the response is helpful, please click "Accept Answer" and upvote it.

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.



image.png (133.6 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.