Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 通过xml的Imageview圆角和遮罩形状在AS 3.0中不起作用_Android_Image_Android Layout - Fatal编程技术网

Android 通过xml的Imageview圆角和遮罩形状在AS 3.0中不起作用

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" />

在创建主题之前检查主题

  • 我想将遮罩应用于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" />
    </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>