再一次面临一个“奇怪”的问题。
我使用Viewpager显示2个单独的图像(Viewpager只包含一个布局和2个图像视图)。 概念是,从本地文件缓存中立即显示低分辨率图像(立即)并同时加载高分辨率图像并显示它。
问题是:只使用低分辨率图片,图片立即显示,一切都很完美,但只要高分辨率图片启用(显示), 如果用户滑动非常快,则屏幕在“短时间”(500ms至1.5s)内保持黑色,并且永远不会显示低分辨率图像。 只是高分辨率的照片..
也许有人遇到类似的问题,任何帮助appriciated :)谢谢!
ViewPager代码:
/**
* Create and add a new page of the image at the given position.
*
* @param collection
* @param position
*/
@Override
public Object instantiateItem (View collection, final int position) {
Log.v(TAG, "instantiateItem: pos: " +position);
final Context context = collection.getContext();
RelativeLayout layout = new RelativeLayout(context);
ImageViewTouch imageView = new ImageViewTouch(context);
ImageViewTouch imageView2 = new ImageViewTouch(context);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
layout.addView(imageView, lp);
layout.addView(imageView2, lp);
imageView.setOnSingleTapConfirmedListener((OnImageViewSingleTapConfirmedListener) context);
imageView2.setOnSingleTapConfirmedListener((OnImageViewSingleTapConfirmedListener) context);
imageView2.setVisibility(View.GONE);
if (position == restorePageNumber) {
loadBitmap(context, position, imageView, imageView2, restoreZoomLevel);
Log.w(TAG, "zoom level regocnized for pos: " + position + " resetting...");
restorePageNumber = Constants.INVALID_INT;
restoreZoomLevel = Constants.INVALID_LONG;
} else {
loadBitmap(context, position, imageView, imageView2, Constants.INVALID_LONG);
}
imageView.setFitToScreen(true);
imageView2.setFitToScreen(true);
activePages.put(position, imageView2);
((ViewPager) collection).addView(layout);
return layout;
}
protected void loadBitmap (Context context, int position, ImageViewTouch imageView, ImageViewTouch imageView2, float restoreZoomLevel) { Photo photo = getPhotoAtPosition(position); Log.v(TAG, "loading photo. pos: " + position + " id: " + photo.getId()); // show small image first if (!(photo instanceof CameraPhoto)) { StorageManager.retrieveBitmapBackgroundWithImageview(context, photo, Photo.SIZE_SMALL, imageView, true, Constants.INVALID_LONG); } // afterwards replace with big image StorageManager.retrieveBitmapBackgroundWithImageview(context, photo, Photo.SIZE_LARGE, imageView2, true, restoreZoomLevel); }
in那些方法(retrieveBitmapBackgroundWithImageview)图像在Background中加载,然后设置为imageview。
设置大位图似乎有些问题。 即使具有大位图的Imageview保持隐藏(View.GONE),并且仅显示本地缓存图像,如果快速滑动,ViewPager在加载页面上保持黑色一段“时间”(如上所述,500ms至1.5s): )
thx:)
答案 0 :(得分:0)
如果您的意思是快速刷到很多页面,那么加载所有这些视图时就会遇到问题。您是否取消/中断超出ViewPager
范围的loadBitmap任务(不在视图或缓存中)?
而且,你在线程中处理并发吗?如果您始终要加载ViewPager's
视图中的页面或首先缓存,则应覆盖Comparator
并在页面上进行比较。比较器可用于PriorityBlockingQueue
,可用于Executor