Android 通过xml的Imageview圆角和遮罩形状在AS 3.0中不起作用
在创建主题之前检查主题 我想将遮罩应用于ImageView,如从到,但它是由多个渐变组成的 起初我用的是Android 通过xml的Imageview圆角和遮罩形状在AS 3.0中不起作用,android,image,android-layout,Android,Image,Android Layout,在创建主题之前检查主题 我想将遮罩应用于ImageView,如从到,但它是由多个渐变组成的 起初我用的是 <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <corners android:radius="36dp" />
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners android:radius="36dp" />
</shape>
无法解析菜单
和操作设置。
为什么答案被接受,但我无法复制?xml文件中缺少什么?即使复制粘贴整个ImageView+形状也无助于仅通过java实现最终解决方案(最初的想法由@pskink提出) 另一个通过xml的简单解决方案 i、 e
和活动中的ImageView.setCliptOutline(true)
。
附加说明:这不适用于不需要任何第三方外部库的可能重复:您只需要@pskink如何在xml中使用它?您不能-您需要在java中设置RoundedBitmapDrawable
getMenuInflater().inflate(R.menu
if (id == R.id.action_settings
ImageView img = (ImageView) findViewById(R.id.img);
Bitmap src1 = BitmapFactory.decodeResource(getResources(), R.drawable.img_port);
RoundedBitmapDrawable dr1 = RoundedBitmapDrawableFactory.create(getResources(), src1);
dr1.setCornerRadius(Math.max(src1.getWidth(), src1.getHeight()) / 10f);
img.setImageDrawable(dr1);
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="15dp" />
<solid/>
</shape>