Grade:
public Bitmap getRoundedShape(Bitmap scaleBitmapImage) { int targetWidth = 50; int targetHeight = 50; Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight,Bitmap.Config.ARGB_8888); canvas = new Canvas(targetBitmap); Path path = new Path(); path.addCircle(((float) targetWidth - 1) / 2, ((float) targetHeight - 1) / 2, (Math.min(((float) targetWidth), ((float) targetHeight)) / 2), Path.Direction.CCW); canvas.clipPath(path); Bitmap sourceBitmap = scaleBitmapImage; canvas.drawBitmap(sourceBitmap, new Rect(0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight()), new Rect(0, 0, targetWidth, targetHeight), null); return targetBitmap; }
View:
<ImageView android:id="@+id/imgView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/btnEdit" android:layout_centerHorizontal="true" android:layout_marginTop="40dp" android:background="@drawable/rounded" android:adjustViewBounds="true" android:gravity="center" android:src="@drawable/happy"/>
Additional styles:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="@android:color/white" /> <stroke android:width="3dip" android:color="#FF0000" /> <corners android:radius="10dp" /> <padding android:bottom="0dp" android:left="0dp" android:right="0dp" android:top="0dp" />
Marcinziolek
source share