再次面臨「奇怪」的問題。Viewpager顯示兩張圖片,分辨率高低分辨率,屏幕黑屏加載時
我使用Viewpager來顯示2個獨立的圖像(Viewpager只包含一個佈局和2個圖像瀏覽)。 這個概念是,從本地文件緩存(立即)顯示一個低解析度圖像,並加載高分辨率的picutre,並顯示它。
問題是:只使用低分辨率圖片,圖片立即顯示並且一切都很完美,但只要啓用了高分辨率圖片(待顯示),如果用戶滑動真的很快,屏幕就會保持黑色對於「短時間」(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); }
(retrieveBitmapBackgroundWithImageview)圖像加載在背景,事後設定爲ImageView的。
它似乎有一些設置大位圖的問題。 即使帶有大位圖的Imageview保持隱藏狀態(View.GONE),並且只顯示本地緩存圖像,如果加載頁面上的ViewPager在某些「時間」(如上,500毫秒到1.5秒)內保持黑屏,如果快速刷新:)
THX :)