Xamarin: Does the carousel page load all the pages at one

假装没事ソ 提交于 2020-01-07 03:44:26

问题


I new in Xamarin form. On Android, I used ViewPager to load images and the user swipe around the pages. Since Android has adapter, all the views are not initialized at once. Now I want to move to Xamarin form and seeing there is Carousel Page. Does it behave the same as ViewPager only load pages as needed?


回答1:


Xamarin.Forms CarouselPage does not support UI virtualization (recycling).

Initialization performance and memory usage can be a problem depending upon the number of pages/children.

The new preferred VisualElement to use is the CarouselView that is basically superseding CarouselPage and it has been optimized for each platform.

Blog: Xamarin.Forms CarouselView

Nuget: Xamarin.Forms.CarouselView (Currently in pre-release)

FYI: I just looked the source for for the Android renderer (CarouselViewRenderer.cs) and it does indeed implement RecyclerView...




回答2:


If you prevent the call to InitializeComponent in the constructor of the page you might have an effect on the load time.

public interface CarouselChildPage {
    void childAppearing();
    void childDissapearing();
}

public partial class MainPage : CarouselPage {
    CarouselPageChild previousPage;

    protected override void OnCurrentPageChanged() {
            base.OnCurrentPageChanged();
            if (previousPage != null)
                previousPage.childDissapearing();

            int index = Children.IndexOf(CurrentPage);
            CarouselPageChild childPage = Children[index] as CarouselPageChild;
            childPage.childAppearing();
            previousPage = childPage;
        }
}


public partial class FriendsListPage : ContentPage, CarouselPageChild {
        bool isLoaded = false;

        public FriendsListPage() {
                // Remove Initialise Component Here    
        }

        public void childAppearing() {
            Logger.log("My Appearing");
            if (!isLoaded){ 
                InitializeComponent();
                isLoaded = true;
            }
        }

        public void childDissapearing() {
            Logger.log("My Disappearing");
        }
}


来源:https://stackoverflow.com/questions/38234911/xamarin-does-the-carousel-page-load-all-the-pages-at-one

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!