@Overridepublic View getView(int position, View convertView, ViewGroup parent) {if (null == convertView) {//.....}Glide.with(context).load(imageUrls[position]).into(holder.imageView);return convertView;}
@Overridepublic void onBindViewHolder(RVViewHolder holder, int position) {Glide.with(MainActivity.this).load(args[position]).into(holder.imageView);}
Glide.with(context).load(UsageExampleListViewAdapter.eatFoodyImages[0]).placeholder(R.mipmap.ic_launcher) // can also be a drawable.into(imageViewPlaceholder);
Glide.with(context).load("http://futurestud.io/non_existing_image.png").error(R.mipmap.future_studio_launcher) // will be displayed if the image cannot be loaded.into(imageViewError);
//使用centerCrop是利用图片图填充ImageView设置的大小,如果ImageView的//Height是match_parent则图片就会被拉伸填充Glide.with(MainActivity.this).load(args[position]).centerCrop().into(holder.imageView);
//使用fitCenter即缩放图像让图像都测量出来等于或小于 ImageView 的边界范围//该图像将会完全显示,但可能不会填满整个 ImageView。Glide.with(MainActivity.this).load(args[position]).fitCenter().into(holder.imageView);
Glide.with( context ).load( gifUrl ).asGif() //判断加载的url资源是否为gif格式的资源.error( R.drawable.full_cake ).into( imageViewGif );
String filePath = "/storage/emulated/0/Pictures/example_video.mp4";Glide.with( context ).load( Uri.fromFile( new File( filePath ) ) ).into( imageViewGifAsBitmap );
Glide.with( context ).load( Images[0] ).skipMemoryCache( true ) //跳过内存缓存.into( imageViewInternet );
Glide.with( context ).load( images[0] ).diskCacheStrategy( DiskCacheStrategy.NONE ) //跳过硬盘缓存.into( imageViewInternet );
DiskCacheStrategy.NONE 什么都不缓存DiskCacheStrategy.SOURCE 仅仅只缓存原来的全分辨率的图像DiskCacheStrategy.RESULT 仅仅缓存最终的图像,即降低分辨率后的(或者是转换后的)DiskCacheStrategy.ALL 缓存所有版本的图像(默认行为)Priority.LOWPriority.NORMALPriority.HIGHPriority.IMMEDIATE
private void loadImageWithHighPriority() {Glide.with( context ).load( mages[0] ).priority( Priority.HIGH ).into( imageViewHero );}private void loadImagesWithLowPriority() {Glide.with( context ).load( images[1] ).priority( Priority.LOW ).into( imageViewLowPrioLeft );Glide.with( context ).load( images[2] ).priority( Priority.LOW ).into( imageViewLowPrioRight );}
//括号中的300,600代表宽和高但是未有作用SimpleTarget target = new SimpleTarget<Bitmap>(300,600) {@Overridepublic void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {holder.imageView.setImageBitmap(resource);}};Glide.with(MainActivity.this).load(args[position]).asBitmap().into(target);
dependencies {// your other dependencies// ...// Glidecompile ‘com.github.bumptech.glide:glide:3.6.1‘// Glide‘s OkHttp Integrationcompile ‘com.github.bumptech.glide:okhttp-integration:1.3.1@aar‘compile ‘com.squareup.okhttp:okhttp:2.5.0‘}
dependencies {// your other dependencies// ...// Glidecompile ‘com.github.bumptech.glide:glide:3.6.1‘// Glide‘s Volley Integrationcompile ‘com.github.bumptech.glide:volley-integration:1.3.1@aar‘compile ‘com.mcxiaoke.volley:library:1.0.8‘}
原文:http://www.cnblogs.com/yuzhongzheng/p/5228354.html