1.加入jar包universal-image-loader-1.9.5.jar
2.在xml文件中
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.imgview"> !!!!<uses-permission android:name="android.permission.INTERNET"/> <application !!! android:name=".App" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
在Activity中写
package com.example.imgview; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.ImageView; import com.nostra13.universalimageloader.core.ImageLoader; public class MainActivity extends AppCompatActivity { String[] images = { "https://img-my.csdn.net/uploads/201407/26/1406383264_8243.jpg", "https://img-my.csdn.net/uploads/201407/26/1406383248_3693.jpg", "https://img-my.csdn.net/uploads/201407/26/1406383243_5120.jpg", "https://img-my.csdn.net/uploads/201407/26/1406383242_3127.jpg", "https://img-my.csdn.net/uploads/201407/26/1406383242_9576.jpg", "https://img-my.csdn.net/uploads/201407/26/1406383242_1721.jpg", "https://img-my.csdn.net/uploads/201407/26/1406383219_5806.jpg", "https://img-my.csdn.net/uploads/201407/26/1406383214_7794.jpg", "https://img-my.csdn.net/uploads/201407/26/1406383213_4418.jpg", "https://img-my.csdn.net/uploads/201407/26/1406383213_3557.jpg", "https://img-my.csdn.net/uploads/201407/26/1406383210_8779.jpg", "https://img-my.csdn.net/uploads/201407/26/1406383172_4577.jpg", "https://img-my.csdn.net/uploads/201407/26/1406383166_3407.jpg", "https://img-my.csdn.net/uploads/201407/26/1406383166_2224.jpg" }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ImageView ImageView = (ImageView) findViewById(R.id.imageView); ImageLoader imageLoader = ImageLoader.getInstance(); imageLoader.displayImage(images[3], ImageView); } }//最后要在layout中键一个xml文件里面写入图片控件