Articles in this section
Category / Section

How to change SpanCount of GridLayout based on screen size in SfListView?

2 mins read

In SfListView, GridLayout arranges the item in a row based on the SpanCount property. The SpanCount can be adjust based on the view size of application either orientation is portrait or landscape.

Refer the following example to adjust the SpanCount based on view size of application,

C#

public partial class GridLayoutPage : ContentPage
{
  protected override void OnSizeAllocated(double width, double height) 
  { 
    base.OnSizeAllocated(width, height); 
 
    if (width > 0 && pageWidth != width) 
    {       
        var size = Application.Current.MainPage.Width / listView.ItemSize; 
        gridLayout.SpanCount = (int)size; 
        listView.LayoutManager = gridLayout; 
     } 
  }
}

 

In the code example, the SpanCount is calculated by screen width and ItemSize property to layout the items. For example, the screen width is 300 and ItemSize is 150 in portrait mode, then SpanCount value would be 2.

Screenshots:

Click here to download the sample.

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied