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

4

1 回答 1

1

尝试在布局上执行缩放动画?

首先创建以下实例变量:

private float mScale = 1f;
private ScaleGestureDetector mScaleDetector;

使用 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;
    }
});

最后,在您的活动中覆盖您的 onTouch 方法,将其连接到您的比例检测器:

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

您可能需要对其进行更多调整才能获得所需的确切解决方案,但这应该有助于您入门:)

希望这可以帮助 :)

于 2013-10-10T03:36:47.287 回答