There is more space than I need in ListView

前端 未结 5 1262
生来不讨喜
生来不讨喜 2021-01-19 19:56

I\'m using StackLayout and ListView to show some part of a view, but the ListView takes more space than I need, and leaves a blank space between the last row of the list and

5条回答
  •  死守一世寂寞
    2021-01-19 20:12

    First, Xamarin suggests not putting a ListView in a ScrollView, since they both offer scrolling and fight with each other. I have personally tried this and it can often cause weird behavior, especially on Android.

    Instead, what I do is use the ListView.Header with the ListView.HeaderTemplate and the ListView.Footer with the ListView.FooterTemplate. Xamarin link here This allows for your exact scenario but without the weird behavior issues. If you would like to see an example of that, let me know.

    If you must must must go with your current layout, you can try to check out this post talking about how the ListView needs to be sized with specific Height and Width or with LayoutOptions since it is not supposed to fit the size of it's contents. There are a couple solutions in that post, none that I have tried yet.

    In this post one of the workarounds that is given, says to add the the ListView to a StackLayout and add that to another StackLayout. Then set the inner StackLayout's VerticalOptions to LayoutOptions.FillAndExpand.

    So it might look like this:

    
      
    
        ....
    
        
          
            
              
                
              
            
          
        
    
        ....
    
      
    
    

提交回复
热议问题