第三方开源库:CircleImageView

本文介绍两种实现圆形图片视图的方法,包括CircleImageView组件的使用及配置,通过自定义属性设置边框颜色与宽度,并展示了如何在布局文件中引用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

CircleImageView

gitHub地址:https://github.com/hdodenhof/CircleImageView

1 效果图:

没有对图片进行优化,若图片过大,容易oom,drawable/a.jpg是大图片。

这里写图片描述

2 Gradle

dependencies {
    ...
    compile 'de.hdodenhof:circleimageview:2.1.0'
    ...
}

3 自定义属性

xmlns:app="http://schemas.android.com/apk/res-auto"

边框颜色

app:civ_border_color="#FF00FF"

边框宽度:

app:civ_border_width="10dp"

4 布局中引用circleImageView

//CircleImageView
<de.hdodenhof.circleimageview.CircleImageView
    android:layout_width="180dp"
    android:layout_height="180dp"
    android:layout_marginTop="10dp"
    android:src="@drawable/b"
    app:civ_border_color="#FF00FF"
    app:civ_border_width="10dp"/>

circleimageview

github地址:https://github.com/crazyandcoder/circleimageview
简书地址:android圆形图片加载使用

1 效果图

这里写图片描述

2 gradle

dependencies {
    ...
    compile 'liji.library.dev:circleimageview:0.1.0'

    //glide是为了演示加载网络图片显示的圆形效果
    compile 'com.github.bumptech.glide:glide:3.7.0'
}

3 添加自定义属性

 xmlns:app="http://schemas.android.com/apk/res-auto"

边框颜色

app:circle_border_color="@color/colorPrimary"

边框宽度:

app:circle_border_width="5dp"

4 布局中使用

对于加载本地图片的话,我们需要设置src而不是background;
对于加载网络图片的话,src、background都可以。

<com.liji.circleimageview.CircleImageView
    android:id="@+id/circleIV4"
    android:layout_width="150dp"
    android:layout_height="150dp"
    app:circle_border_color="@color/colorPrimary"
    app:circle_border_width="5dp"/>
dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout:2.0.4' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.30' implementation 'com.android.support:design:28.0.0' implementation 'com.github.bumptech.glide:glide:4.9.0' implementation 'com.android.support:multidex:1.0.3' //图片/视频选择、预览、编辑与拍照 implementation 'com.contrarywind:Android-PickerView:3.2.7' implementation 'com.github.guoxiaoxing:phoenix:1.0.15' implementation 'cn.yc:YCVideoPlayerLib:2.6.4' implementation 'com.jakewharton:butterknife:8.8.1' annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' //选填 - 图片压缩,开启功能:Phoenix.with().enableCompress(true),获取结果:MediaEntity.getCompressPath() implementation 'com.github.guoxiaoxing:phoenix-compress-picture:1.0.15' implementation 'de.hdodenhof:circleimageview:2.1.0' implementation 'com.zhy:okhttputils:2.6.2' api 'com.just.agentweb:agentweb:4.1.2' // (必选) api 'com.just.agentweb:filechooser:4.1.2' // (可选) api 'com.download.library:Downloader:4.1.2' api 'com.contrarywind:Android-PickerView:3.2.7' api 'com.github.PhilJay:MPAndroidChart:v3.0.0' implementation 'com.imusic.player:video-player:1.0.9' }迁移为新版本
最新发布
03-31
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值