声明网络权限
<!--声明网络权限-->
<uses-permission android:name="android.permission.INTERNET" />
添加Glide依赖
//添加网络图片加载工具Glide的依赖
compile 'com.github.bumptech.glide:glide:3.7.0'
布局文件
<?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"
tools:context=".MainActivity"
android:orientation="vertical">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ImageView>
</LinearLayout>
Glide加载网络图片
package com.lyarn.study;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//虚拟一条网络图片链接
String url="http://contentcms-bj.cdn.bcebos.com/cmspic/dd7b0d8aa276e3a062edf462b4082065.jpeg";
//初始化组件
ImageView imageView=findViewById(R.id.image);
//加载图片
Glide.with(this).load(url).into(imageView);
}
}