protected void onDraw(Canvas canvas) { Path clipPath = new Path(); float radius = 10.0f; float padding = radius / 2; int w = this.getWidth(); int h = this.getHeight(); clipPath.addRoundRect(new RectF(padding, padding, w - padding, h - padding), radius, radius, Path.Direction.CW); canvas.clipPath(clipPath); super.onDraw(canvas); }
public class CustomImageView extends ImageView { public static float radius = 18.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; Path clipPath = new Path(); RectF rect = new RectF(0, 0, this.getWidth(), this.getHeight()); clipPath.addRoundRect(rect, radius, radius, Path.Direction.CW); canvas.clipPath(clipPath); super.onDraw(canvas); } }
RectF r = new RectF(0, 0, w, h); mPath = new Path(); mPath.addRoundRect(r, mCornerRadius, mCornerRadius, Direction.CW); mPath.close();
final Path path = new Path(); path.addRoundRect(new RectF(0,0,getWidth(),getHeight()),10,10,Direction.CW);
RectF roundRect = new RectF(itemRect); Bitmap bitmap = scheme.getSchemeBitmap(getResources()); mPaint.setStyle(Paint.Style.FILL); mPaint.setColor(mSchemeSelectedColor); canvas.drawRoundRect(roundRect, mSchemeCornerRadius, mSchemeCornerRadius, mPaint); roundRect.set(itemRect.left + mBorderSize, itemRect.top + mBorderSize, itemRect.right - mBorderSize, itemRect.bottom - mBorderSize); Path clipPath = new Path(); clipPath.addRoundRect(roundRect, mSchemeCornerRadius, mSchemeCornerRadius, Path.Direction.CW); canvas.save(Canvas.CLIP_SAVE_FLAG); canvas.clipPath(clipPath); canvas.drawBitmap(bitmap, null, roundRect, mPaint); canvas.restore();
@Override protected void dispatchDraw(Canvas canvas) { float height = getHeight(); float top = height - ((LayoutParams) getLayoutParams()).topMargin; Path path = new Path(); RectF rectF = new RectF(0.0f, top, getWidth(), height); path.addRoundRect(rectF, 0.0f, 0.0f, Path.Direction.CW); canvas.clipPath(path); super.dispatchDraw(canvas); }
private class MyMapView extends MapView { public MyMapView(Context context, String apiKey) { super(context, apiKey); } @Override public void draw(Canvas canvas) { Path path = new Path(); RectF r = new RectF(0, 0, this.getWidth(), this.getHeight()); path.addRoundRect(r, 12, 12, Path.Direction.CW); canvas.clipPath(path); super.draw(canvas); } }
public class RoundCornerView extends View{ public RoundCornerView(Context context) { super(context); } public RoundCornerView(Context context, AttributeSet attrs) { super(context, attrs); } public RoundCornerView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } protected void onDraw(android.graphics.Canvas canvas) { Paint paint = new Paint(); paint.setAlpha(255); canvas.translate(0, 30); paint.setColor(Color.BLUE); Path mPath = new Path(); mPath.addRoundRect(new RectF(0, 0, 100,100),20,20, Path.Direction.CCW); canvas.clipPath(mPath, Region.Op.INTERSECT); paint.setColor(Color.GREEN); paint.setAntiAlias(true); canvas.drawRect(0, 0, 120,120,paint); } }
public class ClippedListView extends ListView { public ClippedListView(Context context) { super(context); } public ClippedListView(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void dispatchDraw(Canvas canvas) { float radius = 10.0f; Path clipPath = new Path(); RectF rect = new RectF(0, 0, this.getWidth(), this.getHeight()); clipPath.addRoundRect(rect, radius, radius, Path.Direction.CW); canvas.clipPath(clipPath); super.dispatchDraw(canvas); } }
@Override protected void onDraw(Canvas canvas) { Path clipPath = new Path(); clipPath.addRoundRect(new RectF(canvas.getClipBounds()), RADIUS_IN_PIXELS, RADIUS_IN_PIXELS, Path.Direction.CW); canvas.clipPath(clipPath); super.onDraw(canvas); }
//put your bitmap here Bitmap mIcon11= MainActivity.drawableToBitmap(getResources().getDrawable(R.drawable.crow)); Bitmap output = Bitmap.createBitmap(mIcon11.getWidth(), mIcon11.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); final Rect itemRect = new Rect(0, 0, mIcon11.getWidth(), mIcon11.getHeight()); RectF roundRect = new RectF(itemRect); Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); //your bitmap here Bitmap bitmap = MainActivity.drawableToBitmap(getResources().getDrawable(R.drawable.crow)); mPaint.setStyle(Paint.Style.FILL); mPaint.setColor(Color.WHITE); canvas.drawRoundRect(roundRect, 100, 100, mPaint); roundRect.set(itemRect.left + 5, itemRect.top + 5, itemRect.right - 5, itemRect.bottom - 5); Path clipPath = new Path(); //roundness of border clipPath.addRoundRect(roundRect, 100, 100, Path.Direction.CW); canvas.save(Canvas.CLIP_SAVE_FLAG); canvas.clipPath(clipPath); canvas.drawBitmap(bitmap, null, roundRect, mPaint); canvas.restore(); myImageView.setImageBitmap(output);
@Override protected void onDraw(Canvas canvas) { Path clipPath = new Path(); clipPath.addRoundRect(new RectF(canvas.getClipBounds()), RADIUS_IN_PIXELS, RADIUS_IN_PIXELS, Path.Direction.CW); canvas.clipPath(clipPath); super.onDraw(canvas); }
public class RoundedImageView extends ImageView { public RoundedImageView(Context context) { super(context); } public RoundedImageView(Context context, AttributeSet attrs) { super(context, attrs); } public RoundedImageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override protected void onDraw(Canvas canvas) { int radius = (int) getResources().getDimension(R.dimen.corner_radius); // angle of round corners Path clipPath = new Path(); RectF rect = new RectF(0, 0, this.getWidth(), this.getHeight()); clipPath.addRoundRect(rect, radius, radius, Path.Direction.CW); canvas.clipPath(clipPath); super.onDraw(canvas); } }
public class CustomImageView extends ImageView { public static float radius = 50.0f; // you can change this radius according to your need means how much corner radius you want. Initially I used 18.0f for rounded corners. 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; Path clipPath = new Path(); RectF rect = new RectF(0, 0, this.getWidth(), this.getHeight()); clipPath.addRoundRect(rect, radius, radius, Path.Direction.CW); canvas.clipPath(clipPath); super.onDraw(canvas); } }
public class CustomImageView extends ImageButton { public static float radius = 18.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) { Path clipPath = new Path(); RectF rect = new RectF(0, 0, this.getWidth(), this.getHeight()); clipPath.addRoundRect(rect, radius, radius, Path.Direction.CW); canvas.clipPath(clipPath); super.onDraw(canvas); } }
public class RoundedCornerImageView extends ImageView { private int radius = 10; public RoundedCornerImageView(Context context) { super(context); } protected void onDraw(Canvas canvas) { Path clipPath = new Path(); int w = this.getWidth(); int h = this.getHeight(); clipPath.addRoundRect(new RectF(0, 0, w, h), radius, radius, Path.Direction.CW); canvas.clipPath(clipPath); super.onDraw(canvas); } public RoundedCornerImageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public RoundedCornerImageView(Context context, AttributeSet attrs) { super(context, attrs); } public void setRadius(int radius){ this.radius = radius; this.invalidate(); } }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); //-- draw with white color-- Paint p = new Paint(); p.setColor(Color.WHITE); //-- set shadow, 5dp down, 5 dp left, with radius of 15 dp-- p.setShadowLayer(10,5,5,Color.BLACK); //-- warning, Honeycomb and above only //-- this will reduce draw performance of view //-- but is required to support drawing filters, like shadow, blur etc setLayerType(LAYER_TYPE_SOFTWARE,p); //--basic shapes don't have round corners yet, so use path-- Path pt = new Path(); //-- round rectangle path with 15dp padding (space for shadow) //-- and 10 dp corner radius pt.addRoundRect(new RectF(15,15,getWidth() - 15 ,getHeight() -15 ), 10,10, Path.Direction.CW); //--draw-- canvas.drawPath(pt,p); }
Path clipPath = new Path(); RectF rect = new RectF(0, 0, this.getWidth(), this.getHeight()); clipPath.addRoundRect(rect, radius, radius, Path.Direction.CW); canvas.clipPath(clipPath);
RectF rect = new RectF(0, 0, getWidth(), getHeight()); Path clipPath = new Path(); clipPath.addRoundRect(rect, mRadius, mRadius, Path.Direction.CW); canvas.clipPath(clipPath);
class RoundImageViewClipped extends ImageView { private static final int RADIUS = 32; private RectF mRect; private Path mClip; public RoundImageViewClipped(Context context) { super(context); // setBackgroundColor(0xffffffff); mRect = new RectF(); mClip = new Path(); } @Override public void onDraw(Canvas canvas) { Drawable dr = getDrawable(); if (dr != null) { mRect.set(dr.getBounds()); getImageMatrix().mapRect(mRect); mRect.offset(getPaddingLeft(), getPaddingTop()); mClip.reset(); mClip.addRoundRect(mRect, RADIUS, RADIUS, Direction.CCW); canvas.clipPath(mClip); super.onDraw(canvas); } } }