Android动画:查看直接更改为结束位置

时间:2015-05-15 09:20:40

标签: android animation android-studio objectanimator


我得到一个任务,创建一个像糖果粉碎传奇和流动的Android平台游戏。我尝试了一些关于事件监听器和动画的教程,它运行良好,但是当我为ImageView设置动画来改变它的位置时我遇到了问题。 当我在ImageView(糖果粉碎游戏)上滑动时,我想在两个ImageView之间做出改变位置,它完美地改变了位置,但问题是动画运动不起作用。当我滑动其中一个ImageView(例如右滑动)时,ImageView使用位于其旁边的ImageView改变了位置,但是当我玩糖果粉碎传奇时我看不到动画动画。

我使用2个ObjectAnimator为ImageView设置动画,并在该ImageView上触发Swipe Event时将其一起播放。这是我的动画代码。

final String name = "x";
ImageView target = (ImageView) findViewById(id[x-1][y-1]);
ImageView next = (ImageView) findViewById(id[x-1][y]);
ObjectAnimator aTarget = ObjectAnimator.ofFloat(target, name, target.getX(), (target.getX()+target.getWidth()));
   aTarget.setDuration(1000);
   aTarget.setInterpolator(new LinearInterpolator());
ObjectAnimator aNext = ObjectAnimator.ofFloat(next, name, next.getX(), (next.getX()-next.getWidth()));
   aNext.setDuration(1000);
   aNext.setInterpolator(new LinearInterpolator());
AnimatorSet moveset = new AnimatorSet();
moveset.playTogether(aTarget, aNext);
moveset.start();

我使用ID数组来保存我的ImageView的ID,并使用'for'比较触发滑动事件的View的ID和ID数组中的列表ID,这样我就可以找到选择移动的ImageView(目标)和其他ImageView将选择一个改变位置。 我不明白该代码有什么问题,我从动画教程源代码中获取代码 http://www.101apps.co.za/articles/a-property-animation-tutorial.html
它在我运行应用程序时非常有效,但是当我尝试将它实现到我的应用程序时,我遇到了这个问题。
希望有人可以帮助我,非常感谢。

0 个答案:

没有答案