Android使用Dave Morrissey子采样 - 比例 - 图像视图放大双击和捏合

时间:2015-12-29 12:22:44

标签: android zoom pinch

我试图在双击或用两根手指捏时放大viewPager中的图片。

我使用过Dave Morrissey子采样比例图像视图库。我可以检测到双击,但图像没有任何反应。我也找不到捏手势探测器。

如果你能提供一个简单的例子,请提前多多谢谢。

xml文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
    android:id="@+id/product_img_zoom"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>


</LinearLayout>

viewPager适配器:

final GestureDetector gestureDetector = new GestureDetector(context , new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onDoubleTap(MotionEvent e) {
            if (mProductImgZoom.isReady()) {
                Timber.i("double tap");
                mProductImgZoom.setDoubleTapZoomScale(SubsamplingScaleImageView.SCALE_TYPE_CENTER_CROP );
                mProductImgZoom.setDoubleTapZoomStyle(SubsamplingScaleImageView.ZOOM_FOCUS_FIXED);
                mProductImgZoom.animateScaleAndCenter(2f, new PointF(100, 1500)).start();
            }
            return true;
        }
    });
    @Override
    public int getCount() {
        return bitmap_resources.size();
    }

    @Override
    public Object instantiateItem(final ViewGroup container, int position) {
            View galleryPreview ;
            layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            galleryPreview = layoutInflater.inflate(R.layout.fullscreen_adapter,container,false);
            ButterKnife.bind(this, galleryPreview);
            mProductImgZoom.setImage(ImageSource.uri(bitmap_resources.get(position)));
            container.addView(galleryPreview);
            mProductImgZoom.setZoomEnabled(true);
            mProductImgZoom.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View view, MotionEvent motionEvent) {
                    return gestureDetector.onTouchEvent(motionEvent);

                }
            });
       return galleryPreview;
    }

0 个答案:

没有答案