设置边界限制平移/拖动缩放的自定义相对布局 [英] Setting boundary limits for panning/dragging a Zoomable custom relative layout

查看:494
本文介绍了设置边界限制平移/拖动缩放的自定义相对布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经与以下链接的帮助下实现的缩放和平移/拖动功能在我的自定义相对布局成功。

I've implemented zoom and pan/drag functionality in my custom relative layout successfully with the help of following links.

1)。一个优秀的教程 - 使得检测-的,多点触控

1). An excellent tutorial - making-sense-of-multitouch

2)。 (SO链接)<一个href=\"http://stackoverflow.com/questions/6378904/extending-relativelayout-and-overriding-dispatchdraw-to-create-a-zoomable-vie/6511296#6511296\">Extending RelativeLayout的,并覆盖dispatchDraw()来创建一个可缩放的ViewGroup

2). (SO link) Extending RelativeLayout, and overriding dispatchDraw() to create a zoomable ViewGroup

3)。 (SO链接)<一个href=\"http://stackoverflow.com/questions/10257321/scroll-panning-or-drag-in-custom-layout\">Scroll/Panning或自定义布局拖

3). (SO link) Scroll/Panning or drag in custom layout

下面是我的完整的工作code。

Here's my full working code.

https://gist.github.com/pandeyGitHub/6805840

和我layout.xml如下: -
    

and my layout.xml looks like this:-

<com.myzoomproject.views.ZoomableRelativeLayout
    android:id="@+id/root_pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <com.myzoomproject.views.CustomViewPager
        android:id="@+id/pager_test2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</com.myzoomproject.views.ZoomableRelativeLayout>

我的自定义相对布局包含viewpager在我viewpager每一单页包含2-4 imageviews(一个全屏的ImageView和放大器;一对夫妇的点击小imageviews的)。缩放和放大器;平移网页作品就好。

My Custom relative layout contains a viewpager and each single page in my viewpager contains 2-4 imageviews (one fullscreen imageview & a couple of clickable smaller imageviews). Zooming & panning the page works just fine.

问题1:
但不知何故,我无法将边界限制作为平移功能。该页面将关闭平移上滚动反弹屏幕。

Problem 1: But somehow I'm not able to set boundary limits for panning functionality. The page would pan off the screen on overscrolling.

问题2:
此外,似乎图像视图平移/翻译仅在绘制,但不是在现实。因为他们无法点击了此刻他们摆脱他们的屏幕上原来的位置,与放远;可点击的坐标仍然只限于它们原来的位置。

Problem 2: Also, it seems that image-views are panned/translated only in drawing but not in actuality. because they are not clickable anymore the moment they move away from their original position on screen, & the clickable-coordinates remains confined to their original positions only.

我抬头对SO 链接1 几个类似的问题,的链接2 链接3 但它们都是基于ImageView的变焦和没有自定义布局变焦。

I looked up several similar questions on SO link 1, link 2, link 3 but they all are based on ImageView zoom and not the custom-layout zoom.

所以与他们不同,我没有在我的ZoomableRelativeLayout我imageviews的参考。引用Imageviews,读取位图和放大器;显示它们是由其他类(; MyPagerFragment类MyPagerActivity&AMP)的照顾。此外,在上述环节解决方案依赖于矩阵变换,我恐怕无法在我的情况下使用。

So unlike them, I do not have a reference to my imageviews in my ZoomableRelativeLayout. Referencing the Imageviews, reading the bitmaps & displaying them is taken care of by other classes (MyPagerActivity & MyPagerFragment classes). Also, the solution in above mentioned links relies on matrix transformation, which i probably cannot use in my case.

期待有这方面的帮助。

Looking forward to any help on this.

感谢。

推荐答案

有关问题2,你要调整你的所有relativelayout's儿童帆布正确。你应该在你的scalegesturedetector方法onScaleEnd做到这一点。

For the problem 2, you have to resize the canvas rect of all your relativelayout´s children. You should do this in onScaleEnd method of your scalegesturedetector.

public void resizeChildren() {

    int childCount = this.getChildCount();

    for (int i = 0; i < childCount; i++) {

        MyView child = (MyView)this.getChildAt(i);
        child.setScaleFactor(mScaleFactor);
        child.setCanvasRect(mRect);


    }

}

setScaleFactor()和setCanvasRect()是MyView的方法,这是一个自定义视图我用手指画。

setScaleFactor() and setCanvasRect() are methods for MyView which is a custom View I use for finger painting.

这篇关于设置边界限制平移/拖动缩放的自定义相对布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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