我抬头看图像。这有效,但图像不完全圆......
我该怎么做才能使图像获得完整的图像视图。 android:scaleType =“fitXY”无法正常工作。
这是使图像成为圆形的代码:
public Bitmap getRoundedShape(Bitmap scaleBitmapImage) {
// TODO Auto-generated method stub
int targetWidth = 150;
int targetHeight = 150;
Bitmap targetBitmap = Bitmap.createBitmap(targetWidth,
targetHeight,Bitmap.Config.ARGB_8888);
Canvas 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;
}
添加除以2
我的XML:
<ImageView
android:layout_width="120dp"
app:srcCompat="@drawable/round_image"
android:id="@+id/imageView"
android:background="@drawable/round_image"
android:layout_height="120dp"
android:layout_below="@+id/lblEmail"
android:layout_centerHorizontal="true" />
<ImageView
android:layout_width="120dp"
app:srcCompat="@mipmap/profiel_dark"
android:id="@+id/ivProfilePic"
android:layout_height="120dp"
android:layout_below="@+id/lblEmail"
android:layout_alignLeft="@+id/imageView"
android:layout_alignStart="@+id/imageView"
android:padding="5dp" />