将Tween与逐帧动画相结合

时间:2011-05-23 09:30:51

标签: android tween

我仍然遇到最基本需求的问题。 我想要2个按钮:一个运行一个补间动画,将图像移动50个像素,另一个按钮在该图像上运行逐帧动画。

完成补间动画后,逐帧动画将在错误的位置运行。奇怪的。 我正在使用FillAfter / FillEnabled,

运行补间动画的代码是基本的    TranslateAnimation(0,50,0,0),填充后跟fillEnabled = true。

逐帧代码是    image.setImageDrawable(getResources()getDrawable(RESOURCEID));    ((AnimationDrawable)image.getDrawable())。start();

帮助将不胜感激。

干杯

1 个答案:

答案 0 :(得分:2)

我发现这样做的唯一方法是 首先使用带有新边距的setLayoutParams移动您的imageview位置, 然后你才使用(-x,-y,0,0)启动TranslateAnimation,所以对于我在问题中的具体情况,这是我的代码:

TranslateAnimation tweenAnim = new TranslateAnimation(-1 * XStep, -1  * YStep , 0, 0);
tweenAnim.setDuration(number_of_steps * 750);
tweenAnim.setFillAfter(true);
tweenAnim.setFillEnabled(true);
tweenAnim.setInterpolator(new LinearInterpolator());

 //layout positioning
lp.leftMargin  += XStep;
lp.bottomMargin += YStep;
imageView.setLayoutParams(lp);

Log.v(TAG, "leftMargin=" + lp.leftMargin);
Log.v(TAG, "bottomMargin=" + lp.bottomMargin);

imageView.startAnimation(tweenAnim);

这是一个巨大的痛苦。认真。 感谢http://www.clingmarks.com/?p=400我能够克服它。

相关问题