Created
September 25, 2018 14:46
-
-
Save iamnaran/4da1adf2d4d65a91c72da3407bca442c to your computer and use it in GitHub Desktop.
Custom Image View Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
* [email protected] | |
* 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