Android ViewPager 与可缩放 ImageView

发布于 2024-12-21 13:14:01 字数 557 浏览 1 评论 0原文

我有一个由 ImageViews 制作的 ViewPager,实现如下:

@Override
    public Object instantiateItem(View collection, int position) {
        ImageView iv = new ImageView(ctx);
        if (pageList.size() > position)
            iv.setImageBitmap(pageList.get(position));
        else
            iv.setImageResource(R.drawable.loading);

        iv.setOnTouchListener(this);
        ((ViewPager) collection).addView(iv, 0);
        System.out.println("POS: " + position);
        return iv;
    }

我有机会通过双击(并滑动图像)或捏缩放来缩放 ImageView 吗?

I've got a ViewPager made by ImageViews implemented like this:

@Override
    public Object instantiateItem(View collection, int position) {
        ImageView iv = new ImageView(ctx);
        if (pageList.size() > position)
            iv.setImageBitmap(pageList.get(position));
        else
            iv.setImageResource(R.drawable.loading);

        iv.setOnTouchListener(this);
        ((ViewPager) collection).addView(iv, 0);
        System.out.println("POS: " + position);
        return iv;
    }

Any chance i can have that ImageView zoomable by double tap (and swipe the image) or pinch zoomable?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

心奴独伤 2024-12-28 13:14:01

这是有可能的,我就是这样做的。

我的顶级布局元素是 FrameLayout,它允许多个视图彼此堆叠。 FrameLayout 有两个子项:ViewPagerImageView,我将用它来显示放大的图片。

ImageView 通常是隐藏的。我监听 ViewPager 内图片的触摸事件,并根据这些事件显示、隐藏和平移 ImageView。它运作得相当好。如果需要的话我可以提供更多细节。

It's possible, here's how I did it.

My top level layout element is FrameLayout which allows several views to be stacked on top of each other. The FrameLayout has two children: the ViewPager and an ImageView that I'll use for showing zoomed-in picture.

The ImageView is normally hidden. I listen for touch events on pictures inside the ViewPager and based on those, show and hide and pan the ImageView. It works fairly well. I can give more details if need be.

吃兔兔 2024-12-28 13:14:01

我使用了 Mike Ortiz 的 TouchImageView 类。它并不完美。但这很酷,因为您可以轻松地将其放入!双击缩放动画可能很有趣。捏缩放可以通过双击来触发,这很奇怪。

如果您直接将其放入 ViewPager(通过适配器类)中,它确实可以很好地工作。放大时,您可以自由地左右移动,而不会触发页面更改除非您就在边缘,这真的很酷!

https://github.com/MikeOrtiz/TouchImageView /blob/master/src/com/ortiz/touch/TouchImageView.java

I used the TouchImageView class by Mike Ortiz. It's not perfect. But it's cool because you can drop it in really easily! The double-tap zoom animation can be funny. The pinch zoom can be triggered via double-taps which is weird.

It does work really well if you drop it straight into a ViewPager (via an adapter class). When zoomed in you can freely move left and right without triggering a page change unless you are right on the edge, which is really cool!

https://github.com/MikeOrtiz/TouchImageView/blob/master/src/com/ortiz/touch/TouchImageView.java

桃扇骨 2024-12-28 13:14:01

经过大量搜索,在许多过时和已删除的库中,我发现这个库是最新的,并且在 Viewpagers 中也像一个魅力一样:
https://github.com/davemorrissey/subsampling-scale-image-view

这是它的工作原理:

imageView.setImage(ImageSource.resource(R.drawable.monkey));
// ... or ...
imageView.setImage(ImageSource.asset("map.png"))
// ... or ...
imageView.setImage(ImageSource.uri("/sdcard/DCIM/DSCM00123.JPG"));

After searching a lot and among a lot of outdated and deleted libraries I have found this one which is up to date and also works like a charm inside Viewpagers:
https://github.com/davemorrissey/subsampling-scale-image-view

here's how it works:

imageView.setImage(ImageSource.resource(R.drawable.monkey));
// ... or ...
imageView.setImage(ImageSource.asset("map.png"))
// ... or ...
imageView.setImage(ImageSource.uri("/sdcard/DCIM/DSCM00123.JPG"));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文