Skip to content

Instantly share code, notes, and snippets.

@billynyh
Created November 28, 2012 04:07
Show Gist options
  • Save billynyh/4158971 to your computer and use it in GitHub Desktop.
Save billynyh/4158971 to your computer and use it in GitHub Desktop.
#android rounded corner ImageView
//http://stackoverflow.com/questions/1705239/how-should-i-give-images-rounded-corners-in-android
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.ImageView;
public class RoundedCornerImageView extends ImageView {
private static final String TAG = "RoundedCornerImageView";
public RoundedCornerImageView(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
}
public RoundedCornerImageView(Context context) {
super(context);
}
public RoundedCornerImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
protected void onDraw(Canvas canvas) {
//Log.d(TAG, "onDraw");
Path clipPath = new Path();
int w = this.getWidth();
int h = this.getHeight();
clipPath.addRoundRect(new RectF(0,0,w,h), 10.0f, 10.0f, 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