Glide 加载圆形头像和gif 图
生活随笔
收集整理的這篇文章主要介紹了
Glide 加载圆形头像和gif 图
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
首先到github 上搜索glide 看看版本號
目前是
implementation 'com.github.bumptech.glide:glide:4.9.0'annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
?
布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><ImageViewandroid:id="@+id/img"android:layout_width="120dp"android:layout_height="120dp"/><ImageViewandroid:id="@+id/img2"android:layout_width="120dp"android:layout_height="120dp"/><ImageViewandroid:id="@+id/img3"android:layout_width="120dp"android:layout_height="120dp"/><ImageViewandroid:id="@+id/img4"android:layout_width="120dp"android:layout_height="120dp"/></LinearLayout>
代碼
package com.hly.main;import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
public class ImageActivity extends AppCompatActivity{private ImageView imageView;private ImageView imageView2;private ImageView imageView3;private ImageView imageView4;@Overrideprotected void onCreate(@Nullable Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.image_activity_layout);imageView = findViewById(R.id.img);imageView2 = findViewById(R.id.img2);imageView3 = findViewById(R.id.img3);imageView4 = findViewById(R.id.img4);//普通圖片Glide.with(this).load(R.drawable.image).into(imageView);//圓形圖片Glide.with(this).load(R.drawable.image).circleCrop().into(imageView2);//gif圖Glide.with(this).load(R.drawable.dong).diskCacheStrategy(DiskCacheStrategy.RESOURCE).into(imageView3);//加載網絡圖片,占位圖片Glide.with(this).load("https://raw.githubusercontent.com/leon5458/my_use_image/master/my_use_image/1.jpg").placeholder(R.drawable.image).into(imageView4);}
}
一般Glide.with 上下文,然后是圖片(網絡,本地.gif都可以) 然后是圖片風格然后就是指定圖片布局的地方
寫的時候可以 先打一個 . 后面有提示,可以翻閱查看。
?
當前版本glide 加載gif 圖 不需要指定類型glide 會自動識別的
diskCacheStrategy()方法 說明
DiskCacheStrategy.NONE: 表示不緩存任何內容。
DiskCacheStrategy.DATA: 表示只緩存原始圖片。
DiskCacheStrategy.RESOURCE: 表示只緩存轉換過后的圖片。
DiskCacheStrategy.ALL : 表示既緩存原始圖片,也緩存轉換過后的圖片。
?
?
總結
以上是生活随笔為你收集整理的Glide 加载圆形头像和gif 图的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 5s手机多少钱啊?
- 下一篇: 一般颜色鲜艳的蛇都有剧毒吗