在Android中,默认情况下ImageView是一个矩形.如何在ImageView中将其设置为圆角矩形(将我的Bitmap的所有4个角切掉为圆角矩形)?
android rounded-corners imageview android-image android-imageview
我怎么能ImageView在Android中创建圆形?
我尝试了以下代码,但它没有正常工作.
码:
Bitmap circleBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
BitmapShader shader = new BitmapShader (bitmap, TileMode.CLAMP, TileMode.CLAMP);
Paint paint = new Paint();
paint.setShader(shader);
Canvas c = new Canvas(circleBitmap);
c.drawCircle(bitmap.getWidth()/2, bitmap.getHeight()/2, bitmap.getWidth()/2, paint);
imageView.setImageBitmap(circleBitmap);
Run Code Online (Sandbox Code Playgroud)
圆圈内的图像:

我怎样才能做到这一点?
我正在尝试ImageView在下图中制作一个圆角,但右下角。尝试使用背景形状,但它根本不起作用。Glide 加载的所有图像。我应该使用类似的东西ViewOutlineProvider吗?有没有一种有效的方法来做到这一点?谢谢!
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners
android:radius="2dp"
android:bottomRightRadius="20dp"
android:bottomLeftRadius="0dp"
android:topLeftRadius="0dp"
android:topRightRadius="0dp"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
android android-shape android-shapedrawable material-components material-components-android