一、ImageView标签作用是用于显示图片。

二、ImageView案例:

<ImageView
    android:id="@+id/iv2"
    android:layout_width="250dp"
    android:layout_height="150dp"
    android:background="#FFCC00"
    android:src="@drawable/xrk"
    android:layout_marginTop="10dp"
    android:scaleType="centerCrop"
/>

分析:

android Glide加载本地图片 android imageview加载网络图片_android

 

 至于scaleType属性:

android Glide加载本地图片 android imageview加载网络图片_ide_02

 

 不加scaleType属性样式效果:

android Glide加载本地图片 android imageview加载网络图片_github_03

 

 加上scaleType="centerCrop"效果:

android Glide加载本地图片 android imageview加载网络图片_github_04

 三、使用glide加载第三方网络图片:

首先先打开github,搜索glide如图所示:

android Glide加载本地图片 android imageview加载网络图片_github_05

 

 

 点击后往下翻找到:

android Glide加载本地图片 android imageview加载网络图片_ide_06

 代码:

repositories {
  google()
  jcenter()
}

dependencies {
  implementation 'com.github.bumptech.glide:glide:4.11.0'
  annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
}

 

 

android Glide加载本地图片 android imageview加载网络图片_ide_07

 

 

 使用方式:

在找到相关ImageView标签后:

Glide.with(this).load("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1603653705555&di=65cda6fcaba44bb986829160a3a54710&imgtype=0&src=http%3A%2F%2Ft9.baidu.com%2Fit%2Fu%3D1307125826%2C3433407105%26fm%3D79%26app%3D86%26f%3DJPEG%3Fw%3D5760%26h%3D3240").into(imageView3);

其中:load()里面是一个网络图片地址。

到这里还没结束,显示网络图片需要开启网络权限,到AndroidManifest.xml文件中加入:

<uses-permission android:name="android.permission.INTERNET"/>

加入到这个位置:

android Glide加载本地图片 android imageview加载网络图片_github_08

 

 就可以愉快地加载网络图片啦。