Glide加载网络图片并实现selector效果

分两次加载,使用返回后生成的bitmap来进行分布设置生成StateListDrawable

private void addSeletorFromNet(final String pic1, final String pic2, final ImageView imageView) {
	if(imageView == null || TextUtils.isEmpty(pic1))
		return;
	final StateListDrawable drawable = new StateListDrawable();
    Glide.with(getContext())
		.asBitmap()
		.load(pic1)
		.into(new SimpleTarget<Bitmap>() {
				@Override
				public void onResourceReady(@NotNull Bitmap bitmap, Transition<? super Bitmap> transition) {
					Drawable newDraw = new BitmapDrawable(bitmap);
 					drawable.addState(new int[]{-android.R.attr.state_pressed}, newDraw);
					
					Glide.with(getContext())
						.asBitmap()
						.load(pic2)
						.into(new SimpleTarget<Bitmap>() {
								@Override
								public void onResourceReady(@NotNull Bitmap bitmap, Transition<? super Bitmap> transition) {
									Drawable newDraw = new BitmapDrawable(bitmap);
									drawable.addState(new int[]{android.R.attr.state_pressed}, newDraw);

									imageView.setImageDrawable(drawable);
                                   }
                               });

                   }
               });
   }

猜你喜欢

转载自blog.csdn.net/fanwei4751/article/details/105994991