コード例 #1
0
        private void CalculateLayout(int width, int height)
        {
            rectView.Reset();
            rectView.AddRect(0f, 0f, 1f * Width, 1f * Height, Path.Direction.Cw);

            if (clipManager != null)
            {
                if (width > 0 && height > 0)
                {
                    clipManager.SetupClipLayout(width, height);
                    clipPath.Reset();
                    clipPath.Set(clipManager.CreateMask(width, height));

                    if (RequiresBitmap())
                    {
                        if (clipBitmap != null)
                        {
                            clipBitmap.Recycle();
                        }
                        clipBitmap = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888);
                        Canvas canvas = new Canvas(clipBitmap);

                        if (drawable != null)
                        {
                            drawable.SetBounds(0, 0, width, height);
                            drawable.Draw(canvas);
                        }
                        else
                        {
                            canvas.DrawPath(clipPath, clipManager.GetPaint());
                        }
                    }

                    //invert the path for android P
                    if (Build.VERSION.SdkInt > BuildVersionCodes.OMr1)
                    {
                        bool success = rectView.InvokeOp(clipPath, Path.Op.Difference);
                    }

                    //this needs to be fixed for 25.4.0
                    if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop && ViewCompat.GetElevation(this) > 0f)
                    {
                        try
                        {
                            OutlineProvider = new CustomOutlineProvider(clipManager);
                        }
                        catch
                        {
                            //
                        }
                    }
                }
            }

            PostInvalidate();
        }