我已经尝试了很多次,但我知道我错过了一些东西,你们能解释一下吗? 以下是我尝试过的
<ImageView
android:id="@+id/Dicimage"
android:layout_width="130px"
android:layout_height="100px"
android:src="@drawable/slang"
android:background="@drawable/corner"
android:padding="1dp"/>
在资源文件夹中创建角 XML
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#fff"/>
<stroke android:width="0dp"
android:color="#ff000000"/>
<padding android:left="2dp"
android:top="2dp"
android:right="2dp"
android:bottom="2dp"/>
<corners android:radius="30px"/>
</shape>
我得到的是,边框只是圆角矩形,但图像的形状仍然是矩形
最佳答案
不,这是不可能的。您必须以编程方式执行此操作。
您正在做的是创建圆角背景并在其上绘制可绘制对象。
这是 Romain Guy 撰写的有关如何创建圆角图像的精彩文章:http://www.curious-creature.org/2012/12/11/android-recipe-1-image-with-rounded-corners/
关于android - 如何在android中使用XML布局在 ImageView 中为图像制作圆角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9837145/