Beispiel #1
0
        void SetNativeView()
        {
            CleanUpViewPager();

            var inflater = AViews.LayoutInflater.From(Forms.Context);

            // Orientation BP
            if (Element.Orientation == CarouselViewOrientation.Horizontal)
            {
                nativeView = inflater.Inflate(Resource.Layout.horizontal_viewpager, null);
            }
            else
            {
                nativeView = inflater.Inflate(Resource.Layout.vertical_viewpager, null);
            }

            viewPager = nativeView.FindViewById <ViewPager>(Resource.Id.pager);

            viewPager.Adapter = new PageAdapter(Element);
            viewPager.SetCurrentItem(Element.Position, false);

            // InterPageSpacing BP
            var metrics          = Resources.DisplayMetrics;
            var interPageSpacing = Element.InterPageSpacing * metrics.Density;

            viewPager.PageMargin = (int)interPageSpacing;

            // BackgroundColor BP
            viewPager.SetBackgroundColor(Element.BackgroundColor.ToAndroid());

            viewPager.PageSelected           += ViewPager_PageSelected;
            viewPager.PageScrollStateChanged += ViewPager_PageScrollStateChanged;

            // IsSwipingEnabled BP
            SetIsSwipingEnabled();

            SetNativeControl(nativeView);

            // INDICATORS
            indicators = nativeView.FindViewById <CirclePageIndicator>(Resource.Id.indicator);
            SetIndicators();
        }
Beispiel #2
0
        void CleanUpViewPager()
        {
            if (indicators != null)
            {
                indicators.Dispose();
                indicators = null;
            }

            if (viewPager != null)
            {
                viewPager.PageSelected           -= ViewPager_PageSelected;
                viewPager.PageScrollStateChanged -= ViewPager_PageScrollStateChanged;

                if (viewPager.Adapter != null)
                {
                    viewPager.Adapter.Dispose();
                }
                viewPager.Dispose();
                viewPager = null;
            }
        }