本文共 2229 字,大约阅读时间需要 7 分钟。
package zhangphil.phildemo;import android.graphics.drawable.Drawable;import android.support.annotation.Nullable;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.widget.ImageView;import com.bumptech.glide.Glide;import com.bumptech.glide.Priority;import com.bumptech.glide.load.DataSource;import com.bumptech.glide.load.engine.DiskCacheStrategy;import com.bumptech.glide.load.engine.GlideException;import com.bumptech.glide.request.RequestListener;import com.bumptech.glide.request.RequestOptions;import com.bumptech.glide.request.target.Target;public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ImageView image = (ImageView) findViewById(R.id.image); load(image); } private void load(ImageView image) { RequestOptions options = new RequestOptions() .centerCrop() //.placeholder(R.mipmap.ic_launcher_round) .error(android.R.drawable.stat_notify_error) .priority(Priority.HIGH) //.skipMemoryCache(true) .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC); Glide.with(this) .load(R.drawable.loading) .listener(new RequestListener() { @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { return false; } @Override public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { return false; } }) .apply(options) //.thumbnail(Glide.with(this).load(R.mipmap.ic_launcher)) .into(image); }}