I have a ImageView in Xamarin which has rounded corners. My code worked fine for Android 4.4 and below but Lollipop onward it now has a black background added to it Black Area should be Transparent - https://i.stack.imgur.com/GRFnl.png
public class RoundedImageView : ImageView
{
private int _cornerRadiusPercentage;
private Path _path = null;
public RoundedImageView(Context context, IAttributeSet attrs)
: base(context, attrs)
{
this._cornerRadiusPercentage = attrs.GetAttributeIntValue("http://schemas.boomo.android/roundedImageView", "corner_radius_percentage", 10);
this.SetLayerType(LayerType.Software, null);
}
public RoundedImageView(Activity activity, int cornerRadiusPercentage)
: base(activity)
{
this._cornerRadiusPercentage = cornerRadiusPercentage;
this.SetLayerType(LayerType.Software, null);
}
private void SetPath(Canvas canvas)
{
int offsetLeft = this.PaddingLeft;
int offsetRight = this.PaddingRight;
int offsetTop = this.PaddingTop;
int offsetBottom = this.PaddingBottom;
int cw = canvas.Width - offsetLeft - offsetRight;
int ch = canvas.Height - offsetTop - offsetBottom;
int cornerRadius = (int)((this._cornerRadiusPercentage / 100f) * cw);
_path = new Path();
_path.AddRoundRect(new RectF(offsetLeft, offsetTop, cw, ch), cornerRadius, cornerRadius, Path.Direction.Cw);
_path.Close();
}
protected override void OnDraw(Canvas canvas)
{
//Paint paint = new Paint();
//paint.Color = Color.Transparent;
//paint.Alpha = 254;
//paint.AntiAlias = true;
if (_path == null)
SetPath(canvas);
canvas.ClipPath(_path);
//canvas.DrawPath(_path, paint);
base.OnDraw(canvas);
}
}
*Note The commented out sections are bits I've tried to use to fix the issue