Advertisement
basbasbas

Untitled

Nov 12th, 2024
35
0
5 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. package com.package.name;
  2.  
  3. import android.annotation.SuppressLint;
  4. import android.content.Context;
  5. import android.graphics.Canvas;
  6. import android.graphics.Path;
  7. import android.graphics.RectF;
  8. import android.util.AttributeSet;
  9.  
  10. public class RoundRectCornerImageView extends androidx.appcompat.widget.AppCompatImageView {
  11.  
  12.     private float radius = 120.0f;
  13.     private Path path;
  14.     private RectF rect;
  15.  
  16.     public RoundRectCornerImageView(Context context) {
  17.         super(context);
  18.         init();
  19.     }
  20.  
  21.     public RoundRectCornerImageView(Context context, AttributeSet attrs) {
  22.         super(context, attrs);
  23.         init();
  24.     }
  25.  
  26.     public RoundRectCornerImageView(Context context, AttributeSet attrs, int defStyle) {
  27.         super(context, attrs, defStyle);
  28.         init();
  29.     }
  30.  
  31.     private void init() {
  32.         path = new Path();
  33.     }
  34.  
  35.     @SuppressLint("DrawAllocation")
  36.     @Override
  37.     protected void onDraw(Canvas canvas) {
  38.         rect = new RectF(0, 0, this.getWidth(), this.getHeight());
  39.         path.addRoundRect(rect, radius, radius, Path.Direction.CW);
  40.         canvas.clipPath(path);
  41.         super.onDraw(canvas);
  42.     }
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement