温馨提示×

android中imageview圆角如何实现

小亿
88
2024-04-28 17:27:42
栏目: 编程语言

在Android中,可以通过使用ImageViewBackground属性来为ImageView设置圆角。

以下是一个示例代码来实现ImageView圆角的效果:

<ImageView
    android:id="@+id/image"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:background="@drawable/circle_background"
    android:src="@drawable/your_image"
    android:scaleType="centerCrop" />

然后在drawable文件夹中创建一个circle_background.xml文件,内容如下:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <corners android:radius="50dp" />
</shape>

这样就可以实现ImageView圆角的效果,其中android:radius属性的值可以根据需要进行调整。

0