I'm writing an android app which calls codeline B many times.
Therefore I would like to cache the image 'image123' somewhere for performance reasons / making the app faster and only want to load it once and then just display it from the cache somehow.
Is there a way to achieve this without loading it again and again? Does anybody know ?
Is it important to call invalidate() (codeline C) just to be sure the image is always displayed immediately ? How can I find out when the image is displayed in the imageView exactly ?
Thanks for your help in advance.
// codeline A
ImageView imageView = (ImageView) this.findViewById(R.id.imageView);
// codeline B
imageView.setImageResource(R.mipmap.image123);
// codeline C
imageView.invalidate();
Is there a way to achieve this without loading it again and again?
There is an official tutorial for that: https://developer.android.com/training/displaying-bitmaps/cache-bitmap.html
Is it important to call invalidate() (codeline C) just to be sure the image is always displayed immediately ?
No, just setting a new image resource will automatically lead to a redraw.
How can I find out when the image is displayed in the imageView exactly ?
Use View.post
to run code as soon as drawing is finished.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.