Thursday, 18 February 2016

Xamarin Android detect Android version and perform circular reveal

Working on a simple circular reveal using Animator, I needed to detect if we were running  >=Lollipop or not. This is how I did it. I'll probably refactor this somewhat but here's the headlines:


           
           var _circle = FindViewById<imageview>(Resource.Id.imageView1);
           var currentapiVersion = Android.OS.Build.VERSION.SdkInt;
            if (currentapiVersion >= Android.OS.BuildVersionCodes.Lollipop)
            {
                // Do something for lollipop and above versions
                // get the center for the clipping circle
                int cx = _circle.Width / 2;
                int cy = _circle.Height / 2;

                // get the final radius for the clipping circle
                var finalRadius = (float)Math.Sqrt(cx * cx + cy * cy);

                // create the animator for this view (the start radius is zero)
                Animator anim =
                    ViewAnimationUtils.CreateCircularReveal(_circle, cx, cy, 0, finalRadius);

                // make the view visible and start the animation
                _circle.Visibility = ViewStates.Visible;
                anim.Start();
            }
            else
            {
                _circle.Visibility = ViewStates.Visible;
           }

No comments:

Post a Comment

Comments are moderated, so you'll have to wait a little bit before they appear!