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>
初始化控件之后用工具類加載
//第一個參數(shù)上下文,第二個控件名稱,第三個圖片url地址,第四個參數(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動態(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)文章
詳解Android使GridView橫向水平滾動的實(shí)現(xiàn)方式
Android為我們提供了豎直方向的滾動控件GridView,這篇文章主要介紹了Android使GridView橫向水平滾動的實(shí)現(xiàn)方式,有興趣的可以了解一下2017-05-05Android WebView上實(shí)現(xiàn)JavaScript與Java交互
這篇文章主要介紹了Android WebView上實(shí)現(xiàn)JavaScript與Java交互 的相關(guān)資料,需要的朋友可以參考下2016-03-03Android使用webView加載html頁面的詳細(xì)步驟
Android WebView是Android開發(fā)中提供的一種用于顯示網(wǎng)頁內(nèi)容的組件,它可以加載網(wǎng)頁的url鏈接,也可以加載本地的html文件,下面這篇文章主要給大家介紹了關(guān)于Android使用webView加載html頁面的相關(guān)資料,需要的朋友可以參考下2024-06-06Android開發(fā)設(shè)置RadioButton點(diǎn)擊效果的方法
這篇文章主要介紹了Android開發(fā)設(shè)置RadioButton點(diǎn)擊效果的方法,詳細(xì)分析了Android開發(fā)中RadioButton屬性功能及相關(guān)設(shè)置技巧,需要的朋友可以參考下2017-06-06Android自定義View實(shí)現(xiàn)選座功能
這篇文章主要介紹了Android自定義View實(shí)現(xiàn)選座功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-09-09Android開發(fā)數(shù)據(jù)結(jié)構(gòu)算法ArrayList源碼詳解
這篇文章主要為大家介紹了Android開發(fā)數(shù)據(jù)結(jié)構(gòu)算法ArrayList源碼詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10