如何放大一个动态的布局? [英] How to zoom a dynamic layout?
问题描述
有一个的LinearLayout,并希望addView(LinearLayout中)的结尾,现在我想放大的布局,我应该怎么办?
我已搜查这个类似的问题,并得到了一个解决方案,它提供了一个罐子,但它之前,我吸取了我添加了布局的东西只能放大的布局,它有一个问题是,它每一次显示了两个观点,一是是一部开拓创新的观点,一种是可以放大,就像我说的,这是链接,我该如何解决?谢谢
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
推荐答案
尝试上的布局进行大规模的动画?
Try performing a scale animation on the layout?
通过创建以下实例变量启动:
Start by creating the following instance variables:
private float mScale = 1f;
private ScaleGestureDetector mScaleDetector;
你的启动规模的手势检测,利用ScaleAnimation:
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;
}
});
最后,覆盖您onTouch方法您的活动里面线它到你的规模探测器:
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 :)
希望这有助于:)
这篇关于如何放大一个动态的布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!