2014-09-03 69 views
1

我有一个ImageView动画使用翻译动画无限下降我的图像在屏幕上。我想注册触及ImageView的图像,但是我的onClick处理程序永远不会被调用,除非我点击ImageView的原始位置。注册onclick动画ImageView

有什么方法来识别动画图像被点击

回答

1

一个翻译动画是一个视图动画只会改变其视图视觉绘制,而不是实际位置。您可能需要切换到使用其中一个属性动画,或者编写一个自定义视图动画,它使用setX或setY特别更新视图的位置。对于

示例代码:

public void doCustomAnimation(){ 
    final Float startingPoint= mLittleChef.getX(); 
    Animation animation = new Animation() 
     { 
     @Override 
     protected void applyTransformation(float interpolatedTime, Transformation t) { 
       mLittleChef.setX(startingPoint - (int)(startingPoint/2 * interpolatedTime)); 
     } 

     }; 
    animation.setAnimationListener(new AnimationListener(){ 
    @Override 
    public void onAnimationEnd(Animation animation) { 
     simpleLock= false; 
    } 
    @Override 
    public void onAnimationRepeat(Animation animation) { 
     // TODO Auto-generated method stub 
    } 
    @Override 
    public void onAnimationStart(Animation animation) { 
     // TODO Auto-generated method stub 
    } 
    }); 
    animation.setInterpolator(new LinearInterpolator()); 
    animation.setRepeatCount(1); 
    animation.setRepeatMode(Animation.REVERSE); 
    animation.setDuration(mShortAnimationDuration/2); 
    mLittleChef.startAnimation(animation); 
} 

你可以阅读更多有关视图动画这里:HERE

如果你想使用属性动画:HERE

+0

谢谢你惠特尼。我使用了一个objectAnimator,它工作得很好:-) – user2687482 2014-09-03 23:04:20

0

这可能是因为你并没有真正更新动画后的位置时。

为了实现这个目标,只需拨打setFillEnabled每次执行动画:

animation.setFillEnabled(true);   
+1

这不起作用 – user2687482 2014-09-03 23:04:37