Android开发圆形头像

目前在应用开发中,矩形的头像基本没有了,大多是圆形或圆角矩形,本文简简单单轻轻松松帮你搞定圆形或圆角矩形的头像。

可以自定义控件实现,而本文使用的是第三方开源控件RoundedImageView,改控件支持圆形、椭圆、圆角矩形等,使用非常方便。
添加RoundedImageView依赖
使用RoundedImageView有两种操作方法,实质都是添加库依赖。
方法一: 在Android Studio中,可进入模块设置中添加库依赖。 进入Module结构设置添加库依赖(如下图)

Android开发圆形头像_第1张图片
Paste_Image.png
输入RoundedImageView然后搜索添加。
Android开发圆形头像_第2张图片
Paste_Image.png

方法二: 在Moudle的build.gradle中添加如下代码,添加完之后在Build中进行下Make Module操作(编译下Module),使自己添加的依赖生效。

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.makeramen:roundedimageview:2.2.1'
}```
Layout中使用

添加了库依赖之后,我们就可以使用该控件了。

先看看效果: 
![Paste_Image.png](http://upload-images.jianshu.io/upload_images/5423625-78097e0d0a20d26a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
这里我设置的是圆形:

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/zr"
app:riv_oval="true" />```

控件属性:
riv_border_width: 边框宽度
riv_border_color: 边框颜色
riv_oval: 是否圆形
riv_corner_radius: 圆角弧度
riv_corner_radius_top_left:左上角弧度
riv_corner_radius_top_right: 右上角弧度
riv_corner_radius_bottom_left:左下角弧度
riv_corner_radius_bottom_right:右下角弧度



    

    

   

   
Android开发圆形头像_第3张图片
Paste_Image.png
Android开发圆形头像_第4张图片
Paste_Image.png

你可能感兴趣的:(Android开发圆形头像)