Android實(shí)現(xiàn)圓形圖片或者圓角圖片
Android圓形圖片或者圓角圖片的快速實(shí)現(xiàn),具體內(nèi)容如下
話不多說直接上code
xml文件布局
<LinearLayout android:id="@+id/ll_headpict" android:layout_width="match_parent" android:layout_height="97dp" android:layout_margin="13dp" android:background="@drawable/shape_white_radius10_solid" android:gravity="center_vertical" android:orientation="horizontal" android:paddingLeft="25dp"> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="頭像" android:textColor="@color/color4A4A4A" android:textSize="14sp" android:textStyle="bold" /> <ImageView android:id="@+id/iv_headpict" android:layout_width="60dp" android:layout_height="60dp" android:layout_marginRight="37dp" android:scaleType="fitXY" android:src="@mipmap/ic_headview_demo" /> </LinearLayout>
初始化控件之后用工具類加載
//第一個(gè)參數(shù)上下文,第二個(gè)控件名稱,第三個(gè)圖片url地址,第四個(gè)參數(shù)圓角大小
ViewUtils.loadImageRadius(this, mIvpict, stringUrl, 15);//頭像
ViewUtils.java工具類
/**
* Created by wjw on 2016/11/28
* 倒圓角工具類
*/
public class ViewUtils {
/**
* 圖片加載
* @param context
* @param iv
* @param url
*/
public static void loadImage(Context context, ImageView iv, String url) {
if(null ==context || null==iv){
return;
}
if(Utils.isTxtEmpty(url)){
try {
Glide.with(context).load(R.mipmap.placeholder_icon) .dontAnimate().diskCacheStrategy(DiskCacheStrategy.ALL).into(iv);
}catch (Exception e){
}
}else {
try {
Glide.with(context).load(url) .dontAnimate().diskCacheStrategy(DiskCacheStrategy.ALL).placeholder(R.mipmap.placeholder_icon).into(iv);
} catch (Exception e) {
}
}
}
public static void loadImage(Context context, ImageView iv, int id) {
if(null ==context || null==iv){
return;
}
try {
Glide.with(context).load(id) .dontAnimate().diskCacheStrategy(DiskCacheStrategy.ALL).placeholder(R.mipmap.placeholder_icon).into(iv);
}catch (Exception e){
}
}
/**
* 本地圖片
* @param context
* @param iv
* @param id
* @param radius
*/
public static void loadImage(Context context, ImageView iv, int id,int radius) {
if(null ==context || null==iv){
return;
}
try {
Glide.with(context).load(id) .dontAnimate().diskCacheStrategy(DiskCacheStrategy.ALL).
transform(new GlideRoundTransform(context, radius)).into(iv);
}catch (Exception e){
}
}
public static void setImageResource(ImageView iv, int id) {
if(null!=iv){
iv.setImageResource(id);
}
}
/**
* 加載網(wǎng)絡(luò)圖片(帶圓角)
* @param context
* @param iv
* @param url
* @param radius
*/
public static void loadImageRadius(Context context, ImageView iv, String url, int radius) {
if(null ==context || null==iv){
return;
}
if(Utils.isTxtEmpty(url)){
try {
Glide.with(context).load(R.mipmap.placeholder_icon) .dontAnimate().diskCacheStrategy(DiskCacheStrategy.ALL).
transform(new GlideRoundTransform(context, radius)).into(iv);
}catch (Exception e){
}
}else{
try {
Glide.with(context).load(url) .dontAnimate().diskCacheStrategy(DiskCacheStrategy.ALL).
transform(new GlideRoundTransform(context, radius)).placeholder(R.mipmap.placeholder_icon).into(iv);
}catch (Exception e){
}
}
}
/**
* 加載網(wǎng)絡(luò)圖片(圓形)
* @param context
* @param iv
* @param url
*/
public static void loadImageCircle(Context context, ImageView iv, String url) {
if(null ==context || null==iv){
return;
}
if (Utils.isTxtEmpty(url)) {
try {
Glide.with(context).load(R.mipmap.placeholder_icon) .dontAnimate().diskCacheStrategy(DiskCacheStrategy.ALL).
transform(new GlideCircleTransform(context)).into(iv);
}catch (Exception e){
}
} else {
try {
Glide.with(context).load(url) .dontAnimate().diskCacheStrategy(DiskCacheStrategy.ALL).transform(new GlideCircleTransform(context)).
placeholder(R.mipmap.placeholder_icon).into(iv);
}catch (Exception e){
}
}
}
}
效果如圖圓角圖片

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android將Glide動(dòng)態(tài)加載不同大小的圖片切圓角與圓形的方法
- Android開發(fā)使用Drawable繪制圓角與圓形圖案功能示例
- Android自定義Drawable實(shí)現(xiàn)圓形和圓角
- Android中Glide加載圓形圖片和圓角圖片實(shí)例代碼
- Android自定義控件之圓形、圓角ImageView
- Android實(shí)現(xiàn)圓角矩形和圓形ImageView的方式
- Android自定義view實(shí)現(xiàn)圓形、圓角和橢圓圖片(BitmapShader圖形渲染)
- Android自定義控件之圓形/圓角的實(shí)現(xiàn)代碼
- android 實(shí)現(xiàn)圓角圖片解決方案
- Android基于Fresco實(shí)現(xiàn)圓角和圓形圖片
相關(guān)文章
Flutter實(shí)現(xiàn)紅包動(dòng)畫效果的示例代碼
這篇文章主要為大家詳細(xì)介紹了如何利用Flutter實(shí)現(xiàn)紅包的動(dòng)畫效果,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,感興趣的小伙伴可以了解一下2023-06-06
詳解Android Service與Activity之間通信的幾種方式
這篇文章主要介紹了詳解Android Service與Activity之間通信的幾種方式,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-04-04
Android開發(fā)中用Kotlin編寫LiveData組件教程
LiveData是Jetpack組件的一部分,更多的時(shí)候是搭配ViewModel來使用,相對于Observable,LiveData的最大優(yōu)勢是其具有生命感知的,換句話說,LiveData可以保證只有在組件( Activity、Fragment、Service)處于活動(dòng)生命周期狀態(tài)的時(shí)候才會(huì)更新數(shù)據(jù)2022-12-12
android實(shí)現(xiàn)掃描網(wǎng)頁二維碼進(jìn)行網(wǎng)頁登錄功能
這篇文章主要介紹了android掃描網(wǎng)頁二維碼進(jìn)行網(wǎng)頁登錄效果,掃描成功之后跳轉(zhuǎn)進(jìn)入主頁,具體實(shí)現(xiàn)代碼大家參考下本文2017-12-12
Android仿微信和QQ多圖合并框架(類似群頭像)的實(shí)現(xiàn)方法
這篇文章主要給大家介紹了關(guān)于Android仿微信和QQ多圖合并框架的相關(guān)資料,其實(shí)就是我們平時(shí)所見的群聊頭像,文中通過示例代碼介紹的非常詳細(xì),對各位Android開發(fā)者們具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-12-12
Android為textView設(shè)置setText的時(shí)候報(bào)錯(cuò)的講解方案
今天小編就為大家分享一篇關(guān)于Android為textView設(shè)置setText的時(shí)候報(bào)錯(cuò)的講解方案,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2019-03-03

