UIVirtualization support to handle the numerous data in Xamarin.Android Carousel
Carousel control can handle the numerous data using UI virtualization by maintaining only the view port items into it.
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:https://www.syncfusion.com/downloads/support/directtrac/general/ze/VirtualizationSample-954378307
Conclusion
I hope you enjoyed learning about UIVirtualization support to handle the numerous data in Carousel.
You can refer to our Xamarin.Android Carousel feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.
For current customers, you can check out
our components from the License and Downloads page. If you are new to Syncfusion, you can try our
30-day free
trial
to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!