0

There is a linearlayout ,and want to "addView(linearlayout)" at the end,now I want zoom the layout, how I should do ? I have searched this similar question ,and got a solution ,it provided a jar,but it only can zoom the layout before I draw something on the layout that I added, and it has a problem is that it show two view every time,one is the orignal view,one is can be zoomed just as I said, this is the link,How I can fix ? Thanks

enter link description here

Community
  • 1
  • 1

1 Answers1

1

Try performing a scale animation on the layout?

Start by creating the following instance variables:

private float mScale = 1f;
private ScaleGestureDetector mScaleDetector;

Initiate your scale gesture detector, utilizing ScaleAnimation:

mScaleDetector = new ScaleGestureDetector(this, new ScaleGestureDetector.SimpleOnScaleGestureListener() 
{                                   
    @Override
    public boolean onScale(ScaleGestureDetector detector) 
    {
        float scale = 1 - detector.getScaleFactor();

        float prevScale = mScale;
        mScale += scale;

        if (mScale < 0.1f) // Minimum scale condition:
            mScale = 0.1f;

        if (mScale > 10f) // Maximum scale condition:
            mScale = 10f;

        ScaleAnimation scaleAnimation = new ScaleAnimation(1f / prevScale, 1f / mScale, 1f / prevScale, 1f / mScale, detector.getFocusX(), detector.getFocusY());
        scaleAnimation.setDuration(0);
        scaleAnimation.setFillAfter(true);
        myContainer.startAnimation(scaleAnimation);

        return true;
    }
});

Finally, override your onTouch method inside your activity to wire it up to your scale detector:

@Override
public boolean onTouchEvent(MotionEvent event) 
{
    mScaleDetector.onTouchEvent(event);
    return super.onTouchEvent(event);
}

You'll probably need to tweak it a bit more to get the exact solution you want, but this should help get you started :)

Hope this helps :)

Gil Moshayof
  • 16,633
  • 4
  • 47
  • 58
  • I want to zoom the layout by finger,just as multipoint zoom,thanks for your answer all in all:) – user2516334 Oct 10 '13 at 05:21
  • I added a more complete solution for you: – Gil Moshayof Oct 10 '13 at 06:02
  • Thanks ,I got it ,and it works ,but not very statable,maybe should tweak it a bit,but the performance is scale relative full the screen , – user2516334 Oct 10 '13 at 08:46
  • great, glad i could be of assistance. If this post helped u, feel free to accept the answer :) – Gil Moshayof Oct 10 '13 at 08:56
  • So sorry ,last comment is not complete,it didn't satify my requirement completely.I hope the scale relatives the full screen , the edge of view still along the screen while it is zooming ,but not like a picture ,which moved to the centre or other place of the screen.Personally,I think this performance can be drawed by canvas,but not clearly about the concrete details.:) – user2516334 Oct 10 '13 at 09:05
  • Stack Overflow is not a place where other developers write all the code for you, its a place where other people can set you on the right path. I hope you didn't expect me to write the entire solution for you. I simply don't have time for that, and also, I would expect to paid by a bit more than an upvote. I understood from you that my solution helped you, and considering i did take time out of my schedule to do so, some appreciation would be nice. – Gil Moshayof Oct 10 '13 at 09:13
  • Thanks a lot ,I am new ,Some rules are not very clear,and so sorry for that,I got it and get the wright way to study.Thanks again. – user2516334 Oct 10 '13 at 09:28