简体   繁体   English

如何将图像加载到不在活动布局中的 imageView?

[英]How to load an image into an imageView that is not in the active layout?

I am Making an Background app and want to load the images when the first page is running but i need to load the image into ImageView in another activity which is not active(Maybe it is not possible i don't know).我正在制作一个后台应用程序,并希望在第一页运行时加载图像,但我需要在另一个未激活的活动中将图像加载到 ImageView 中(也许我不知道这是不可能的)。 This maybe seem a silly question to some of u but tried to solve it for like 2 days and I cant figure it out.对于你们中的一些人来说,这可能是一个愚蠢的问题,但试图解决它大约 2 天,但我无法弄清楚。 So i thought i should ask here.所以我想我应该在这里问。 I also Tried to find the answer on the internet but i couldn't find the answer on the internet.我也试图在互联网上找到答案,但我无法在互联网上找到答案。 If this not possible then please send suggestions if you have any about what should i do.如果这不可能,那么如果您对我应该做什么有任何建议,请发送建议。 Thanks For Reading And Thinking about it.感谢您的阅读和思考。

I'm not sure if I understand you right, but it looks like you simply need to pass image uri by Intent or other way, get it inside onResume() and then just display it.我不确定我的理解是否正确,但看起来您只需要通过Intent或其他方式传递image uri ,将其放入onResume() ,然后就可以显示它。 I don't see any point in loading image into ImageView which isn't visible on the screen.我认为将图像加载到ImageView没有任何意义,这在屏幕上不可见

Of course if you need to load image from background thread into ImageView which is visible you can use当然,如果您需要将图像从后台线程加载到可见的ImageView ,您可以使用

runOnUiThread(new Runnable() {
    public void run() {
        // here you load image
    }
});

I am assuming that, you are trying load image into inactive imageview to achieve faster loading of image.我假设您正在尝试将图像加载到非活动图像视图中以实现更快的图像加载。 You can use Picasso to cache image before loading it, so when you need the image you'll have it on cache.您可以在加载图像之前使用Picasso缓存图像,因此当您需要图像时,您可以将其缓存。

Singleton picasso instance单例毕加索实例

Picasso picasso =  new Picasso.Builder(context).memoryCache(new LruCache(context)).build();

preload the image预加载图像

 picasso.load("https://image..").fetch();

load the image into imageview将图像加载到 imageview

ImageView target = findViewById(..);
picasso.load("https://image..").into(target);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM