图片加载框架之Gilde详细讲解(二)

来源:互联网 发布:淘宝图片锁有用么 编辑:程序博客网 时间:2024/06/04 17:50
gilde的使用案例:
1)基本使用
布局.txt
2)加载网络图片
Glide.with(this).load("http://img1.imgtn.bdimg.com/it/u=2615772929,948758168&fm=21&gp=0.jpg").into(ivGlide1);
3)加载资源文件
Glide.with(this).load(R.mipmap.ic_launcher).into(ivGlide2);
4)加载本地图片
String gifUrl = "http://b.hiphotos.baidu.com/zhidao/pic/item/faedab64034f78f066abccc57b310a55b3191c67.jpg";
Glide.with(this).load(gifUrl).placeholder(R.mipmap.ic_launcher).into(ivGlide4);
5)在家资源文件
Glide.with(this).load(R.drawable.loading).asGif().placeholder(R.mipmap.ic_launcher).into(ivGlide5);
6)加载本地
String gifPath = Environment.getExternalStorageDirectory()+"/meinv2.jpg";

File gifFile = new File(gifPath);
Glide.with(this).load(gifFile).placeholder(R.mipmap.ic_launcher).into(ivGlide6);
7)加载本地小视频和快照
String videoPath =Environment.getExternalStorageDirectory()+"/video.mp4";;
File videoFile = new File(videoPath);
Glide.with(this).load(Uri.fromFile(videoFile)).placeholder(R.mipmap.ic_launcher).into(ivGlide7);
8)设置缩略图比例,先加载缩略图,在加载原图
String urlPath="/storage/emulated/0/meinv1.jpg";
Glide.with(this).load(new File(urlPath)).thumbnail(0.1f).centerCrop().placeholder(R.mipmap.ic_launcher).into(ivGlide8);
9)线建立一个缩略图对象,先加载缩略图,在加载原图
DrawableRequestBuilder thumbnailRequest= Glide.with(this).load(new File(urlPath));
Glide.with(this).load(Uri.fromFile(videoFile)).thumbnail(thumbnailRequest).centerCrop().placeholder(R.mipmap.ic_launcher).into(ivGlide9);

2)recyclerView中加载图片
布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>

<include layout="@layout/titlebar"></include>

<android.support.v7.widget.RecyclerView
android:id="@+id/rv_glide"
android:layout_width="match_parent"
android:layout_height="match_parent">

</android.support.v7.widget.RecyclerView>
</LinearLayout>

1)初始化recyclerview
GlideAdapter glideAdapter = new GlideAdapter(this);
rvGlide.setAdapter(glideAdapter);
rvGlide.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
(2)编写适配器
a)准备数据
准备数据.txt
b)加载图片
加载图片.txt
c)加载动画
加载动画.txt

githup项目地址:https://github.com/benyondall/atgui
原创粉丝点击