Glide简介:
Android常用的图片加载框架有Glide和Fresco,Picasso比Glide更加简洁和轻量,Glide比Picasso功能更为丰富。今天我们来讲解Glide的基本用法。目前我们使用Glide的稳定版本是3.7.0,要想使用Glide,我们首先要将这个库引入到我们的项目当中。
Glide引用:(添加Glide库到build.gradle)
implementation 'com.github.bumptech.glide:glide:3.7.0'
Glide加载网络图片需要申请网络权限,给项目申请网络权限:
<uses-permission android:name="android.permission.INTERNET"/>
添加了Glide库和网络权限,我们接下来测试Glide的基本用法:
首先我们尝试加载一张图片,这是一张图片的地址:
"https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=1" +
"00&size=b4000_4000&sec=1552447551&di=fee8ca3e043e8b2c68d68648e5a93547&src=http" +
"://pic.90sjimg.com/back_pic/00/00/52/00/4901c7e259661a93e1423c8c62341da8.jpg"
首先在布局文件添加一个ImageView控件:
<?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">
<ImageView