Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.package.name;
- import android.annotation.SuppressLint;
- import android.content.Context;
- import android.graphics.Canvas;
- import android.graphics.Path;
- import android.graphics.RectF;
- import android.util.AttributeSet;
- public class RoundRectCornerImageView extends androidx.appcompat.widget.AppCompatImageView {
- private float radius = 120.0f;
- private Path path;
- private RectF rect;
- public RoundRectCornerImageView(Context context) {
- super(context);
- init();
- }
- public RoundRectCornerImageView(Context context, AttributeSet attrs) {
- super(context, attrs);
- init();
- }
- public RoundRectCornerImageView(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- init();
- }
- private void init() {
- path = new Path();
- }
- @SuppressLint("DrawAllocation")
- @Override
- protected void onDraw(Canvas canvas) {
- rect = new RectF(0, 0, this.getWidth(), this.getHeight());
- path.addRoundRect(rect, radius, radius, Path.Direction.CW);
- canvas.clipPath(path);
- super.onDraw(canvas);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement