如何在Android中使用XML布局在图像视图中为图像制作圆角 [英] how to make a rounded corners for an image in image view using XML layout in android
问题描述
我已经尝试了很多次,但是我知道我想念一些东西,请你们解释一下. 以下是我尝试过的内容
<ImageView
android:id="@+id/Dicimage"
android:layout_width="130px"
android:layout_height="100px"
android:src="@drawable/slang"
android:background="@drawable/corner"
android:padding="1dp"/>
在资源文件夹中创建了Corner 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创建圆角图像的精彩文章: Created Corner XML in resource folder What i am getting is, the border is only rounded rectangle but the image is still rectangle in shape No, that is not possible. You have to do it programmatically. What you are doing is create rounded corners background and draw the drawable over it. Here's the great article of how to create rounded corners image from Romain Guy: http://www.curious-creature.org/2012/12/11/android-recipe-1-image-with-rounded-corners/ 这篇关于如何在Android中使用XML布局在图像视图中为图像制作圆角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! <?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>