How to use Universal image Loader for loading resources locally

你。 提交于 2019-11-29 06:49:30

问题


I want to know how can i use nostra13 / Android-Universal-Image-Loader for displaying Images locally i.e from drawable folder along with the Memorycache. I want to use it with ViewPager. any help will be greatly appreciated.


回答1:


To load images from assets and drawables you should take ExtendedImageDownloader from example project (this class is not a part of library yet) and also set it to configuration.

UPD: Loading local resources (from drawable, assets, content provider) works out of the box since UIL v1.8.0.

See README:

String imageUri = "assets://image.png"; // from assets
String imageUri = "drawable://" + R.drawable.image; // from drawables (only images, non-9patch)

NOTE: Use drawable:// only if you really need it! Always consider the native way to load drawables — ImageView.setImageResource(...) instead of using of ImageLoader.




回答2:


Whenever More than one image load from resource dynamically (@runtime) than prefer these one:

String imgUri = "drawable://" + getResources().getIdentifier(imgName, "drawable", getActivity().getPackageName());

Here, imgName = Name of image in resource



来源:https://stackoverflow.com/questions/14098993/how-to-use-universal-image-loader-for-loading-resources-locally

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!