Skip to content

Instantly share code, notes, and snippets.

@iamnaran
Created September 25, 2018 14:46
Show Gist options
  • Save iamnaran/4da1adf2d4d65a91c72da3407bca442c to your computer and use it in GitHub Desktop.
Save iamnaran/4da1adf2d4d65a91c72da3407bca442c to your computer and use it in GitHub Desktop.
Custom Image View Android
package com.upasarga.elibrary.helper;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.widget.ImageView;
/**
* Created by NaRan on 23,Sep,2018.
* Copyright (c) UT Pvt. Ltd. All rights reserved.
* nrn.panthi@gmail.com
* MacBook
**/
public class CustomImageView extends ImageView {
public static float radius = 10.0f;
public CustomImageView(Context context) {
super(context);
}
public CustomImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onDraw(Canvas canvas) {
//float radius = 36.0f;
@SuppressLint("DrawAllocation") Path clipPath = new Path();
@SuppressLint("DrawAllocation") RectF rect = new RectF(0, 0, this.getWidth(), this.getHeight());
clipPath.addRoundRect(rect, radius, radius, Path.Direction.CW);
canvas.clipPath(clipPath);
super.onDraw(canvas);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment