We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

UIVirtualization support to handle the numerous data in carousel

Platform: Xamarin.Android |
Control: SfCarousel |
Published Date: June 28, 2018 |
Last Revised Date: June 21, 2019

 

Carousel control can handle the numerous data using UI virtualization by maintaining only the view port items into it.

 

xamarin_virtualization.png

 

 

Properties are used to achieve UI Virtualization options

 

Properties

Data Type

Default Value

Usage

EnableVirtualization

 

Boolean

false

Enable or disable UI Virtualization options in carousel control

ItemsSource

IEnumerable

null

To load the collection of data’s

 

The following code example illustrates the way to use the UI Virtualization feature on carousel control.

 

In MainActivity:

C#

public class MainActivity : Activity
{
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
 
        LinearLayout linearLayout = new LinearLayout(this);
        linearLayout.SetBackgroundColor(Color.White);
        linearLayout.LayoutParameters = new ViewGroup.LayoutParams(500, 500);
        SfCarousel sfCarousel = new SfCarousel(this);
        sfCarousel.EnableVirtualization= true; 
        sfCarousel.ViewMode = ViewMode.Linear;
        sfCarousel.ItemWidth = 400;
        sfCarousel.ItemHeight = 400;
 
        //collection
        List<string> collection = new List<string>();
        for (int i = 1; i <= 10000;i++)
        {
            collection.Add("Item " + i.ToString());
        }
        sfCarousel.ItemsSource = collection;
        sfCarousel.Adapter = new MyCarouselAdapter(this);
        linearLayout.AddView(sfCarousel);
        SetContentView(linearLayout);
 
    }
}
 

 

Adapter View Definitions:

C#

/// <summary>
/// My carousel adapter.
/// </summary>
public class MyCarouselAdapter:ICarouselAdapter
{
    #region myContext
    /// <summary>
    /// My context.
    /// </summary>
    Context myContext;
    #endregion
 
    #region MyCarouselAdapter
    /// <summary>
    /// Initializes a new instance of the <see cref="T:LoadMore.MyCarouselAdapter"/> class.
    /// </summary>
    /// <param name="context">Context.</param>
    public MyCarouselAdapter(Context context)
    {
        myContext = context;
    }
    #endregion
 
    #region view renderer method
    public View GetItemView(SfCarousel carousel, int index)
    {
        TextView textView = new TextView(myContext);
        textView.SetBackgroundColor(Color.Indigo);
        textView.TextAlignment = TextAlignment.Center;
        textView.Gravity = GravityFlags.Center;
        textView.TextSize = 15;
        textView.Text = (carousel.ItemsSource as List<string>)[index];
        textView.SetTextColor(Color.White);
        return textView;
    }
    #endregion
}

 

 

Sample:

http://www.syncfusion.com/downloads/support/directtrac/general/ze/VirtualizationSample-954378307

 

 

 

2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon