结合上双指缩放多个视图,并用不同的视图替换它们 [英] Combine multiple views on pinch zoom and replace them with a different View

查看:192
本文介绍了结合上双指缩放多个视图,并用不同的视图替换它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这是管理它里面的多个子视图Horizo​​ntalScrollView(父)的子类。每个视图由一个矩形,它下面和TextView的几行(见图片)。我在这添加捏缩放手势,所以当用户双指缩放它们之间的两个手指按缩放比例进行缩放的所有子视图。因此,例如,我的第一个手指在一月和第二手指上月,我在所有三个视图(一月,二月和三月)的比例做的捏。我只缩放x方向。此外,我已经定义了最小和特定视图的最大宽度。

I have a subclass of HorizontalScrollView(parent) which is managing multiple child views inside it. Each View consists of a rectangle, few lines below it and TextView(See image). I have added pinch zoom gesture in it so when user pinch zoom all the child views which are between the two fingers are scaled according to scale factor. So for example my first finger is on Jan and second finger on March and I am doing pinch in, all three views (Jan,Feb and March) are scaling. I am scaling only in x direction. Also I have defined minimum and maximum width of a particular view.

现在我要扩展这个功能。我想包括一些在里面分层功能。因此,如果在一个特定的层次结构中所有观点都是以最小的宽度,如果我试图进一步扩大下来(按捏缩放),那么所有这些意见必须由不同的视图替换。

Now I want to extend this feature. I want to include some kind of hierarchic feature in it. So if all the views in a particular hierarchy are in minimum width and if I try to further scale them down(by pinch zoom), then all these views must be replaced by a different View.

举例来说,假设一月,二月和三月是一个层次结构,并通过双指缩放我缩减他们自己的最小宽度。如果我试图进一步扩展了下去,然后代替这三个观点总会有另一个View。

For example, say Jan,Feb and March is in one hierarchy and by pinch zoom I scaled down them to their minimum width. If I further try to scale it down, then in place of these three views there comes another View.

该功能的目的是说,我有10年在Horizo​​ntalScrollView个月。所以,我共有120次(10年×12个月)。所以,如果我缩小了一年的所有月份,并进一步尝试扩大下来,那么我应该以每年视图替代其12月份视图。

The purpose of this feature is that say I have months of a 10 year in HorizontalScrollView. So I have total 120 views(10 years*12 months). So if I scaled down all months of a year and further try to scale them down, then I should replace 12 month views by a year view.

希望我在我的问题清楚。谁能告诉我该怎么做。

Hopefully I am clear in my question. Can anyone tell me how to do it.

编辑:
我存储阵列中的国家[]子视图比例因子和增加我的code两种方法

I am storing scale factor of the child views in an array state[] and added two methods in my code

     boolean checkstate()
     {
         if(state[6]<=0.3f &&state[7]<=0.3f &&state[8]<=0.3f  )
             return true;
         else
             return false;
     }


    void changewithparent()
    {
        LinearLayout parent=(LinearLayout)takeparent();
        parent.removeViewAt(6);
        parent.removeViewAt(6);
        parent.removeViewAt(6);

        //parent.requestLayout();
        View v=kk.getView(6, null, parent);
        v.setBackgroundColor(Color.GREEN);
        parent.addView(v, 0);
     }

此外,在ScaleListener我加入以下行

Also in ScaleListener I have added the following lines

    //start and end are the indices of child views which are scaling
for(int i=start;i<=last;i++)
            {
                LinearLayout ll=(LinearLayout)pp.getChildAt(i);
                DrawView view=(DrawView)ll.findViewById(R.id.drawview);

                view.mScaleFactor=mScaleFactor;
                view.invalidate();
                state[i]=view.sf;   updating the scale factor in parent by taking the value from child view
                change= checkstate();
                if(change==true)
                    changewithparent();

            } 

但每当到达子视图的最小限制我的应用程序崩溃,我试图与父视图来取代它们。

But my application is crashing whenever the minimum limit of child view is reached and I am trying to replace them with parent View

推荐答案

既然你知道你的年视图将多宽基于月份的最小宽度,您可以包括一年的看法与它的可见性设置为走了,然后根据需要几个月甚至一年的交换知名度?

Since you know how wide your year view will be based on the min width of the months, could you include a year view with it's visibility set to GONE, then swap visibility of the months and Year as needed?

为了使它更加动感一点,你可以为存储它的状态,在这种情况下将包括件事要告诉你,如果是在最小或最大宽度每一个视图对象。缩放时,你会检查状态更改每个对象。如果你的状态检查通过一些规则(在最小宽度例如12个月对象,或者10年以上对象的最大宽度),你会要求一个布局,然后将取代使用适当的新的研究观点,并更新您的状态对象。

To make it a bit more dynamic, you could have an object for each view which stores it's state, which in this case would include something to tell you if it's at minimum or maximum width. When scaling, you would check each object for state changes. If your state check passes some rule (e.g. 12 month objects at min width, or a 10 year object above max width), you would request a layout which would then replace the views with the appropriate new views, and update your state objects.

这篇关于结合上双指缩放多个视图,并用不同的视图替换它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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