lateinit var imageLoader:ImageLoader
在 onCreate
val config =
ImageLoaderConfiguration.Builder(mContext)
.threadPoolSize(5)
.threadPriority(Thread.MIN_PRIORITY + 2)
.defaultDisplayImageOptions(DisplayImageOptions.createSimple())
.build()
imageLoader = ImageLoader.getInstance()
imageLoader.init(config);
并用于:例如在回收站视图中绑定:
var options : DisplayImageOptions?
val strFileName :String = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString()+"/FolderName/"+"filename.jpg"
val imgFile = File(strFileName)
if(strFileName!="null" && imgFile.exists()) {
options = DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.ic_logo_white)
.showImageForEmptyUri(R.drawable.ic_logo_white)
.showImageOnFail(R.drawable.ic_logo_white)
.cacheInMemory(true)
.cacheOnDisk(true)
.considerExifParams(true)
.bitmapConfig(Bitmap.Config.RGB_565)
.build()
if (strFileName.contains("http")) {
imageLoader.displayImage(
strFileName,
view.imageView,
options
)
} else {
imageLoader.displayImage("file:///"+strFileName, view.imageView)
}
}