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

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
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值