示例#1
0
        private static float[] GetRadii(RoundedCornerStackLayout control)
        {
            var radius = (float)(control.CornerRadius);

            if (radius == -1)
            {
                radius = (float)control.Width / 8;
            }
            else
            {
                radius *= 2;
            }

            var topLeft     = control.RoundedCorners.ToLower().Contains("topleft") ? radius : 0;
            var topRight    = control.RoundedCorners.ToLower().Contains("topright") ? radius : 0;
            var bottomLeft  = control.RoundedCorners.ToLower().Contains("bottomleft") ? radius : 0;
            var bottomRight = control.RoundedCorners.ToLower().Contains("bottomright") ? radius : 0;

            if (control.RoundedCorners.ToLower().Contains("all"))
            {
                topLeft = topRight = bottomLeft = bottomRight = radius;
            }

            var radii = new[] { topLeft, topLeft, topRight, topRight, bottomRight, bottomRight, bottomLeft, bottomLeft };

            return(radii);
        }
示例#2
0
        private static void DrawBorder(Canvas canvas, RoundedCornerStackLayout control, Path path)
        {
            if (control.BorderColor == Xamarin.Forms.Color.Transparent ||
                control.BorderThickness <= 0)
            {
                return;
            }

            var paint = new Paint();

            paint.AntiAlias   = true;
            paint.StrokeWidth = control.BorderThickness;
            paint.SetStyle(Paint.Style.Stroke);
            paint.Color = control.BorderColor.ToAndroid();

            canvas.DrawPath(path, paint);

            paint.Dispose();
        }
示例#3
0
        public static Drawable GenerateBackgroundWithShadow(RoundedCornerStackLayout control, Android.Views.View child, Android.Graphics.Color backgroundColor,
                                                            Android.Graphics.Color shadowColor,
                                                            int elevation,
                                                            GravityFlags shadowGravity)
        {
            var radii = GetRadii(control);

            int DY;

            switch (shadowGravity)
            {
            case GravityFlags.Center:
                DY = 0;
                break;

            case GravityFlags.Top:
                DY = -1 * elevation / 3;
                break;

            default:
            case GravityFlags.Bottom:
                DY = elevation / 3;
                break;
            }

            var shapeDrawable = new ShapeDrawable();

            shapeDrawable.Paint.Color = backgroundColor;
            shapeDrawable.Paint.SetShadowLayer(elevation, 0, DY, shadowColor);

            child.SetLayerType(LayerType.Software, shapeDrawable.Paint);

            shapeDrawable.Shape = new RoundRectShape(radii, null, null);

            var drawable = new LayerDrawable(new Drawable[] { shapeDrawable });

            drawable.SetLayerInset(0, elevation, elevation, elevation, elevation);

            child.Background = drawable;
            return(drawable);
        }