处理图像关闭 UI 线程 - 说明
Processing images off UI thread - clarification
我正在阅读 Processing Bitmap's off the UI Thread tutorial ( http://developer.android.com/training/displaying-bitmaps/process-bitmap.html ) 我现在对 loadBitmap
方法。 AsyncDrawable 构造函数中使用的 mPlaceHolderBitmap 属性到底是什么?我知道它是位图,但实际上代表什么?与原始图像相关联的位图或用户定义的 'empty' 位图。在这里提供一些帮助将不胜感激。
public void loadBitmap(int resId, ImageView imageView) {
if (cancelPotentialWork(resId, imageView)) {
final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
final AsyncDrawable asyncDrawable =
new AsyncDrawable(getResources(), mPlaceHolderBitmap, task);
imageView.setImageDrawable(asyncDrawable);
task.execute(resId);
}
}
变量 mPlaceHolderBitmap
包含一个占位符位图。这是一些默认位图,将在您执行 loadBitmap()
方法后立即显示。它将一直显示,直到异步加载所需的位图。
从服务器加载图像(例如用户图像)时,通常会使用占位符。你用它来填充 space 一些有意义的东西,直到加载正确的图像。另请注意,无法始终加载正确的图像 - 在我们的用户图像示例中 - 并非所有用户都定义了他们的图像,否则可能存在阻止数据下载的网络问题。
我正在阅读 Processing Bitmap's off the UI Thread tutorial ( http://developer.android.com/training/displaying-bitmaps/process-bitmap.html ) 我现在对 loadBitmap
方法。 AsyncDrawable 构造函数中使用的 mPlaceHolderBitmap 属性到底是什么?我知道它是位图,但实际上代表什么?与原始图像相关联的位图或用户定义的 'empty' 位图。在这里提供一些帮助将不胜感激。
public void loadBitmap(int resId, ImageView imageView) {
if (cancelPotentialWork(resId, imageView)) {
final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
final AsyncDrawable asyncDrawable =
new AsyncDrawable(getResources(), mPlaceHolderBitmap, task);
imageView.setImageDrawable(asyncDrawable);
task.execute(resId);
}
}
变量 mPlaceHolderBitmap
包含一个占位符位图。这是一些默认位图,将在您执行 loadBitmap()
方法后立即显示。它将一直显示,直到异步加载所需的位图。
从服务器加载图像(例如用户图像)时,通常会使用占位符。你用它来填充 space 一些有意义的东西,直到加载正确的图像。另请注意,无法始终加载正确的图像 - 在我们的用户图像示例中 - 并非所有用户都定义了他们的图像,否则可能存在阻止数据下载的网络问题。