2017-09-25 121 views
-1

我将活动1中的图像从url加载到图像视图中(使用滑动)。当我切换到活动2时,我断开了我的网络连接,并且我需要在另一个图像视图中加载相同的图像。我该如何实现这一目标?这可以通过使用通过滑动缓存在某处的图像来完成。将缓存图像从一项活动传递到另一项活动

+1

此解决方案将是有帮助的https://stackoverflow.com/questions/32406489/glide-how-to-find-if-the-image-is-already-cached-and-use-the-cached-version –

回答

1

在你的活动1

转换的ImageView使用滑行创建自己的缓存文件夹和缓存图像转换成it.It可以创建位图

imageView.buildDrawingCache(); 
Bitmap bmp = imageView.getDrawingCache(); 

Intent intent = new Intent(this, Activity2.class); 
intent.putExtra("img", bmp); 

在活性2

Bitmap bitmap = (Bitmap) intent.getParcelableExtra("img"); 
    imageView.setImageBitmap(bitmap); 
0

而是缓存图像可在整个应用程序中轻松访问

Glide.with(yourImageView.getContext()) 
       .load("your url") 
       .asBitmap() 
       .placeholder(R.drawable.place_holder) 
       .error(R.drawable.place_holder) 
       .into(new SimpleTarget<Bitmap>() { 
        @Override 
        public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) { 

       //Create a folder for caching and add images from here 

        } 
       }); 
相关问题