Skip to content Skip to sidebar Skip to footer

How To Zoom A Dynamic Layout?

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

Solution 1:

Try performing a scale animation on the layout?

Start by creating the following instance variables:

privatefloat mScale = 1f;
private ScaleGestureDetector mScaleDetector;

Initiate your scale gesture detector, utilizing ScaleAnimation:

mScaleDetector = newScaleGestureDetector(this, newScaleGestureDetector.SimpleOnScaleGestureListener() 
{                                   
    @OverridepublicbooleanonScale(ScaleGestureDetector detector) 
    {
        floatscale=1 - detector.getScaleFactor();

        floatprevScale= mScale;
        mScale += scale;

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

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

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

        returntrue;
    }
});

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

@OverridepublicbooleanonTouchEvent(MotionEvent event) 
{
    mScaleDetector.onTouchEvent(event);
    returnsuper.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 :)

Post a Comment for "How To Zoom A Dynamic Layout?"