compile 'com.youth.banner:banner:1.4.9'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
public class BannerImageLoader extends ImageLoader {
@Override
public void displayImage(Context context, Object path, ImageView imageView) {
com.nostra13.universalimageloader.core.ImageLoader imageLoader = com.nostra13.universalimageloader.core.ImageLoader.getInstance();
imageLoader.displayImage((String) path,imageView);
}
}
public class MApp extends Application {
@Override
public void onCreate() {
super.onCreate();
//初始化组件
ImageLoaderConfiguration configuration = new ImageLoaderConfiguration.Builder(this).build();
ImageLoader.getInstance().init(configuration);
}
}
public class MainActivity extends AppCompatActivity {
String[] urls = {"https://img-my.csdn.net/uploads/201407/26/1406383265_8550.jpg",
"https://lh4.googleusercontent.com/--dq8niRp7W4/URquVgmXvgI/AAAAAAAAAbs/-gnuLQfNnBA/s160-c/A%252520Song%252520of%252520Ice%252520and%252520Fire.jpg",
"https://lh5.googleusercontent.com/-7qZeDtRKFKc/URquWZT1gOI/AAAAAAAAAbs/hqWgteyNXsg/s160-c/Another%252520Rockaway%252520Sunset.jpg",
"https://lh3.googleusercontent.com/--L0Km39l5J8/URquXHGcdNI/AAAAAAAAAbs/3ZrSJNrSomQ/s160-c/Antelope%252520Butte.jpg",
"https://lh6.googleusercontent.com/-8HO-4vIFnlw/URquZnsFgtI/AAAAAAAAAbs/WT8jViTF7vw/s160-c/Antelope%252520Hallway.jpg",
"https://lh4.googleusercontent.com/-WIuWgVcU3Qw/URqubRVcj4I/AAAAAAAAAbs/YvbwgGjwdIQ/s160-c/Antelope%252520Walls.jpg"};
List<String> list = new ArrayList<>();
private Banner banner;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
banner = (Banner) findViewById(R.id.banner);
//图片加载器
banner.setImageLoader(new BannerImageLoader());
//设置图片集合
banner.setImages(Arrays.asList(urls));
//启动轮播
banner.start();
}
}