Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.text;
- import android.content.Context;
- import android.graphics.Canvas;
- import android.graphics.Path;
- import android.graphics.RectF;
- import android.util.AttributeSet;
- public class RoundedImageView extends ImageView
- {
- float radius = 10.0f; // angle of round corners
- Path clipPath;
- RectF rect;
- public RoundedImageView(Context context)
- {
- this(context, null);
- clipPath = new Path();
- rect = new RectF();
- }
- public RoundedImageView(Context context, AttributeSet attrs) {
- this(context, attrs, 0);
- clipPath = new Path();
- rect = new RectF();
- }
- public RoundedImageView(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- clipPath = new Path();
- rect = new RectF();
- }
- @Override
- protected void onDraw(Canvas canvas) {
- rect.set(0, 0, this.getWidth(), this.getHeight());
- clipPath.addRoundRect(rect, radius, radius, Path.Direction.CW);
- canvas.clipPath(clipPath);
- super.onDraw(canvas);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement