我有一个非常长的图像,我需要屏幕从头到尾悬停在它上面。
有任何建议如何实现吗?
谢谢, 伊兰
答案 0 :(得分:0)
如果您确定内存足以加载所需的位图,您只需在后台线程中加载位图,然后在可见的ImageViewer对象上显示位图的所需部分,这里是屏幕外位图处理的示例代码< / p>
class BitmapWorkerTask extends AsyncTask<Integer, Void, Bitmap> {
private final WeakReference<ImageView> imageViewReference;
private int data = 0;
public BitmapWorkerTask(ImageView imageView) {
// Use a WeakReference to ensure the ImageView can be garbage collected
imageViewReference = new WeakReference<ImageView>(imageView);
}
// Decode image in background.
@Override
protected Bitmap doInBackground(Integer... params) {
data = params[0];
return decodeSampledBitmapFromResource(getResources(), data, 100, 100));
}
// Once complete, see if ImageView is still around and set bitmap.
@Override
protected void onPostExecute(Bitmap bitmap) {
if (imageViewReference != null && bitmap != null) {
final ImageView imageView = imageViewReference.get();
if (imageView != null) {
imageView.setImageBitmap(bitmap);
}
}
}
}