android Studio 图片圆角andriod studio
时间: 2023-10-11 20:10:30 浏览: 120
实现图片圆角的方法可以通过以下两种方式:
1. 使用 XML 属性
在布局文件中使用 ImageView 控件,并设置如下属性:
```xml
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image"
android:background="@drawable/rounded_corner"
android:padding="10dp" />
```
其中,@drawable/image 是图片资源,@drawable/rounded_corner 是一个 XML 文件,用于设置圆角效果。在 drawable 文件夹中新建一个 XML 文件,命名为 rounded_corner.xml,代码如下:
```xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="10dp" />
</shape>
```
这里设置了圆角半径为 10dp,可以根据实际需求进行调整。
2. 使用 Glide 或 Picasso 库
Glide 和 Picasso 都是常用的图片加载库,它们提供了设置圆角图片的方法。使用 Glide 库加载图片,只需要在代码中添加如下代码:
```java
Glide.with(this)
.load(R.drawable.image)
.transform(new RoundedCorners(10))
.into(imageView);
```
其中,RoundedCorners(10) 表示设置圆角半径为 10dp。使用 Picasso 库也类似,只需要添加如下代码:
```java
Picasso.get()
.load(R.drawable.image)
.transform(new RoundedCornersTransformation(10, 0))
.into(imageView);
```
这里的 RoundedCornersTransformation(10, 0) 表示设置圆角半径为 10dp,边框宽度为 0。可以根据实际需求进行调整。
阅读全文
相关推荐


















