亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android實(shí)現(xiàn)圓形圖片或者圓角圖片

 更新時間:2021年06月24日 12:01:02   作者:qq_孤小狼  
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)圓形圖片或者圓角圖片的代碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

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í)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android中三種注入事件方法比較

    Android中三種注入事件方法比較

    這篇文章主要介紹了Android中三種注入事件方法比較,本文分別講解了使用內(nèi)部APIs、使用instrumentation對象、直接注入事件到設(shè)備/dev/input/eventX等3種方法,需要的朋友可以參考下
    2015-02-02
  • 詳解Android使GridView橫向水平滾動的實(shí)現(xiàn)方式

    詳解Android使GridView橫向水平滾動的實(shí)現(xiàn)方式

    Android為我們提供了豎直方向的滾動控件GridView,這篇文章主要介紹了Android使GridView橫向水平滾動的實(shí)現(xiàn)方式,有興趣的可以了解一下
    2017-05-05
  • Android WebView上實(shí)現(xiàn)JavaScript與Java交互

    Android WebView上實(shí)現(xiàn)JavaScript與Java交互

    這篇文章主要介紹了Android WebView上實(shí)現(xiàn)JavaScript與Java交互 的相關(guān)資料,需要的朋友可以參考下
    2016-03-03
  • Android使用webView加載html頁面的詳細(xì)步驟

    Android使用webView加載html頁面的詳細(xì)步驟

    Android WebView是Android開發(fā)中提供的一種用于顯示網(wǎng)頁內(nèi)容的組件,它可以加載網(wǎng)頁的url鏈接,也可以加載本地的html文件,下面這篇文章主要給大家介紹了關(guān)于Android使用webView加載html頁面的相關(guān)資料,需要的朋友可以參考下
    2024-06-06
  • Android實(shí)現(xiàn)加法計(jì)算器

    Android實(shí)現(xiàn)加法計(jì)算器

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)加法計(jì)算器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-03-03
  • Android開發(fā)設(shè)置RadioButton點(diǎn)擊效果的方法

    Android開發(fā)設(shè)置RadioButton點(diǎn)擊效果的方法

    這篇文章主要介紹了Android開發(fā)設(shè)置RadioButton點(diǎn)擊效果的方法,詳細(xì)分析了Android開發(fā)中RadioButton屬性功能及相關(guān)設(shè)置技巧,需要的朋友可以參考下
    2017-06-06
  • Android如何防止apk程序被反編譯(尊重勞動成果)

    Android如何防止apk程序被反編譯(尊重勞動成果)

    作為Android應(yīng)用開發(fā)者,不得不面對一個尷尬的局面,就是自己辛辛苦苦開發(fā)的應(yīng)用可以被別人很輕易的就反編譯出來,天下痛苦之事莫過于此啊,本文會介紹一種防止apk程序被反編譯的方法,感興趣的朋友可以了解下哦
    2013-01-01
  • Android自定義View實(shí)現(xiàn)選座功能

    Android自定義View實(shí)現(xiàn)選座功能

    這篇文章主要介紹了Android自定義View實(shí)現(xiàn)選座功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-09-09
  • 淺談Android中多線程切換的幾種方法

    淺談Android中多線程切換的幾種方法

    本篇文章主要介紹了淺談Android中多線程切換的幾種方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-01-01
  • Android開發(fā)數(shù)據(jù)結(jié)構(gòu)算法ArrayList源碼詳解

    Android開發(fā)數(shù)據(jù)結(jié)構(gòu)算法ArrayList源碼詳解

    這篇文章主要為大家介紹了Android開發(fā)數(shù)據(jù)結(jié)構(gòu)算法ArrayList源碼詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-10-10

最新評論