我正在阅读UI线程教程(http://developer.android.com/training/displaying-bitmaps/process-bitmap.html)上的Processing Bitmap,现在我对loadBitmap方法有疑问。 AsyncDrawable构造函数中使用的mPlaceHolderBitmap属性到底是什么?我知道这是位图,但实际上代表什么?位图与原始图像或用户定义的“空”位图绑定在一起。一些帮助将不胜感激。

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()方法后立即显示。它将一直显示,直到异步加载所需的位图为止。

从服务器加载图像(例如用户图像)时,通常会使用占位符。您可以使用它来填充一些有意义的东西,直到加载正确的图像为止。另请注意,无法始终加载正确的映像-在我们的用户映像示例中-并非所有用户都定义了映像,否则可能会出现网络问题,阻止数据下载。

08-18 07:13