Image enlargement problem with universal image downloader and viewer

I would like to use ImageViewZoom with Universal Image Loader in ImagePagerActivity.

I can enlarge the image. Swipe the following image. But I run into a problem when the image is in the Zoom position.

enter image description here

If the image is enlarged, and I am in the center, if I want to see the right part of the same image and swipe the screen to the left, it will go to the next image. Please help me with this.

here is my xml code:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="1dip" > <it.sephiroth.android.library.imagezoom.ImageViewTouch android:layout_weight="1" android:id="@+id/image" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scaleType="fitCenter" /> <ProgressBar android:id="@+id/loading" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:visibility="gone" /> </FrameLayout> 

EDIT:

Thanks NOSTRA, now I can control the scaling and slide using the code below. But the problem is with multi-touch. I can’t zoom with two fingers.

Here is my previous code (works fine with two fingers):

 public class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener { @Override public boolean onScale( ScaleGestureDetector detector ) { Log.d( LOG_TAG, "onScale" ); float span = detector.getCurrentSpan() - detector.getPreviousSpan(); float targetScale = mCurrentScaleFactor * detector.getScaleFactor(); if ( mScaleEnabled ) { targetScale = Math.min( getMaxZoom(), Math.max( targetScale, getMinZoom()-0.1f ) ); zoomTo( targetScale, detector.getFocusX(), detector.getFocusY() ); mCurrentScaleFactor = Math.min( getMaxZoom(), Math.max( targetScale, getMinZoom()-1.0f ) ); mDoubleTapDirection = 1; invalidate(); return true; } return false; } } 

And here is the Modified:

 public class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener { @Override public boolean onScaleBegin(ScaleGestureDetector detector) { externalScaleListener.onScaleBegin(); return super.onScaleBegin(detector); } @Override public void onScaleEnd(ScaleGestureDetector detector) { externalScaleListener.onScaleEnd(mCurrentScaleFactor); } } 
+6
source share
2 answers

You must first be able to listen to image scaling. ImageViewTouch does not support this function (for example, gesture-imageview supports it), so you must implement it yourself.

Modify ImageViewTouch.java as follows:

 public class ImageViewTouch extends ImageViewTouchBase { ... private OnPageScaleListener externalScaleListener; public void setOnScaleListener(OnPageScaleListener onScaleListener) { this.externalScaleListener = onScaleListener; } public interface OnPageScaleListener { void onScaleBegin(); void onScaleEnd(float scale); } @Override protected void onZoom(float scale) { super.onZoom(scale); if (!mScaleDetector.isInProgress()) { mCurrentScaleFactor = scale; externalScaleListener.onScaleEnd(scale); } } public class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener { @Override public boolean onScaleBegin(ScaleGestureDetector detector) { externalScaleListener.onScaleBegin(); return super.onScaleBegin(detector); } ... @Override public void onScaleEnd(ScaleGestureDetector detector) { externalScaleListener.onScaleEnd(mCurrentScaleFactor); } } ... } 

Then use the following ViewPager implementation in your application:

 import android.content.Context; import android.support.v4.view.ViewPager; import android.util.AttributeSet; import android.view.MotionEvent; /** * {@link ViewPager} which can be deactivated (ignore touch events) * * @author Sergey Tarasevich * @created 19.07.2012 */ public class DeactivableViewPager extends ViewPager { private boolean activated = true; public DeactivableViewPager(Context context) { super(context); } public DeactivableViewPager(Context context, AttributeSet attrs) { super(context, attrs); } public void activate() { activated = true; } public void deactivate() { activated = false; } @Override public boolean onInterceptTouchEvent(MotionEvent event) { if (activated) { try { return super.onInterceptTouchEvent(event); } catch (Exception e) { // sometimes happens return true; } } else { return false; } } @Override public boolean onTouchEvent(MotionEvent event) { try { return super.onTouchEvent(event); } catch (Exception e) { return true; } } } 

Then, in your ViewPager adapter, you must install the following zoom receiver for your ImageViewTouch:

 ImageViewTouch imageView = ...; imageView.setOnScaleListener(new OnPageScaleListener() { @Override public void onScaleBegin() { viewPager.deactivate(); } @Override public void onScaleEnd(float scale) { if (scale > 1.0) { viewPager.deactivate(); } else { viewPager.activate(); } } }); imageLoader.displayImage(url, imageView, ...); 

And do not forget to set large values ​​for maxImage***ForMemoryCache in the ImageLoader configuration, so the UIL will not reduce the original images when decoding to bitmaps:

 ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext()) ... .memoryCacheExtraOptions(3000, 3000) ... .build(); 
+8
source

I am having problems with pre-enlarged images in the viewPager, but now it is ok and solved the problem.

You need to look for the ImageViewTouchBase class for this line:

 protected DisplayType mScaleType = DisplayType.NONE; 

then change it to:

 protected DisplayType mScaleType = DisplayType.FIT_TO_SCREEN; 

By default, DisplayType is set to NONE, its simple, just use FIT_TO_SCREEN, and your images will have a default size when changing to viewPager.

Greetings


You can set these properties so that the image always matches the screen.

 <it.sephiroth.android.library.imagezoom.ImageViewTouch android:id="@+id/iv_pager_image" android:layout_width="fill_parent" android:layout_height="fill_parent" android:adjustViewBounds="true" android:contentDescription="@string/descr_image" android:scaleType="matrix" /> 
0
source

All Articles