查看传呼机+的ImageView +双指缩放+旋转 [英] View Pager + ImageView +Pinch Zoom + Rotation

查看:242
本文介绍了查看传呼机+的ImageView +双指缩放+旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要实现双指缩放的ImageView的,在查看传呼机类似于默认的Andr​​oid库。我发现多个源在GitHub上,但缩放和滑动只是工作只有第一张图像。

I want to implement Pinch Zoom on Imageview, with in View Pager similar to Default Android Gallery. I have found multiple source over GitHub, But the zoom and sliding just work for only first image.

我曾尝试:

1)。 TouchImageView

2。)的PhotoView

3)的Andr​​oid触摸图库

以上所有的链接工作正常的单张图像视图。但是,当涉及到在查看传呼机的图像,他们有一些小问题,只有正常工作在查看传呼机第一张图像。当我们滚动到第三第四图像视图寻呼机,拖拽功能工作不正常,如果图像被放大。

All the above links works fine for single image view. But when it comes to Images in View pager, They have some glitches and only works fine for first image in the View Pager. When we scroll over to 3rd 4th image in view pager, Dragging functionality not working as expected if the image is zoomed.

请,如果任何人都知道这样做有什么好处库,然后提供我的联系他们。

Please if any one knows any good library for doing this, then provide me the link for them.

推荐答案

编辑2:实例code一直推到TouchImageView的主分支。这里是一个<一个href="https://github.com/MikeOrtiz/TouchImageView/blob/master/src/com/ortiz/touch/ViewPagerExampleActivity.java">link到例如活动和<一href="https://github.com/MikeOrtiz/TouchImageView/blob/master/src/com/ortiz/touch/ExtendedViewPager.java">link到ExtendedViewPager 。

EDIT 2: Example code has been pushed to the master branch of TouchImageView. Here is a link to the example activity and a link to the ExtendedViewPager.

编辑:添加code修改实例链接TouchImageView。注意:您将需要最新的code,这是目前在Dev分支。在未来,这将包括在V1.2.0。你知道你有最新的code如果TouchImageView覆盖canScrollHorizo​​ntally。

added code adapting the example link to TouchImageView. Note: you will need the latest code, which is currently in the dev branch. In the future, this will be included in v1.2.0. You know you have the latest code if TouchImageView overrides canScrollHorizontally.

第1步:扩展ViewPager并覆盖canScroll调用canScrollHorizo​​ntallyFroyo

Step 1: Extend ViewPager and override canScroll to call canScrollHorizontallyFroyo.

public class ExtendedViewPager extends ViewPager {

public ExtendedViewPager(Context context) {
    super(context);
}

public ExtendedViewPager(Context context, AttributeSet attrs) {
    super(context, attrs);
}

@Override
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
    if (v instanceof TouchImageView) {
        return ((TouchImageView) v).canScrollHorizontallyFroyo(-dx);
    } else {
        return super.canScroll(v, checkV, dx, x, y);
    }
}

}

第二步:修改TouchImageView加入canScrollHorizo​​ntallyFroyo:

Step 2: Modify TouchImageView by adding canScrollHorizontallyFroyo:

public boolean canScrollHorizontallyFroyo(int direction) {
    return canScrollHorizontally(direction);
}

第三步:您的活动

public class TouchImageViewActivity extends Activity {

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ExtendedViewPager mViewPager = (ExtendedViewPager) findViewById(R.id.view_pager);
        setContentView(mViewPager);
        mViewPager.setAdapter(new TouchImageAdapter());
    }

    static class TouchImageAdapter extends PagerAdapter {

            private static int[] images = { R.drawable.img1, R.drawable.img2, R.drawable.img3 };

            @Override
            public int getCount() {
                    return images.length;
            }

            @Override
            public View instantiateItem(ViewGroup container, int position) {
                    TouchImageView img = new TouchImageView(container.getContext());
                    img.setImageResource(images[position]);
                    container.addView(img, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
                    return img;
            }

            @Override
            public void destroyItem(ViewGroup container, int position, Object object) {
                    container.removeView((View) object);
            }

            @Override
            public boolean isViewFromObject(View view, Object object) {
                    return view == object;
            }

    }
}

第四步:的main.xml

Step 4: main.xml

<com.example.touch.ExtendedViewPager 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/view_pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />


TouchImageView实际上是我的项目。我现在有中的 https://github.com/MikeOrtiz/TouchImageView/树的/ dev> Dev分支与ViewPagers整合,这将被推到主在即将到来的版本。不幸的是,此修复程序仅适用于API 14,自蜂窝较大,早期不叫 canScrollHorizo​​ntally 。如果你需要支持旧的API,那么你就需要在你的ViewPager实现一种解决方法。 <一href="http://stackoverflow.com/questions/7774642/scroll-webview-horizontally-inside-a-viewpager">Here就是一个例子。


TouchImageView is actually my project. I currently have a fix in the dev branch for integration with ViewPagers, which will be pushed to master in an upcoming release. Unfortunately, this fix is only applicable for API 14 and greater since honeycomb and earlier do not call canScrollHorizontally. If you need to support older APIs, then you will need to implement a workaround in your ViewPager. Here is an example.

这篇关于查看传呼机+的ImageView +双指缩放+旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆