android安卓实现圆形头像效果(使用第三方开源库)

实现圆形头像方法有很多,此处使用个人认为最为方便,以及最为快速的一种方法,使用第三方开源库。此开源库提供了一个第三方ImageView的控件:RoundedImageView。

实现步骤:

第一步:引入第三方开源库(使用的开发工具为Android Studio)

在build.gradle中引入需要的开源库


dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    
    compile 'com.makeramen:roundedimageview:2.2.1'      // 此处为引入开源库代码
}

接着点击同步(Sync now)即可引入成功

第二步:布局中使用此第三方控件

        <com.makeramen.roundedimageview.RoundedImageView
            android:id="@+id/home_listview_logo"
            android:src="@mipmap/icon"
            android:layout_gravity="center"
            app:riv_oval="true"
            android:layout_width="50dp"
            android:layout_height="50dp" />

注意:由于是第三方的控件,所以需要带上长长的 com.makeramen.roundedimageview.RoundedImageView,还有一点需要注意,图片地址需要修改为项目中存在的图片

到这里效果应该都已经能出来了,非常简单有没有。

控件的更多属性可供进行设定:

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:右下角弧度
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值