gpt4 book ai didi

android - 为动画 ImageView 注册 onclick

转载 作者:行者123 更新时间:2023-11-30 02:41:48 25 4
gpt4 key购买 nike

我有一个 ImageView,我使用平移动画将我的图像无限地拖放到屏幕上。我想注册对 ImageView 进行的触摸操作,但是我的 onClick 处理程序永远不会被调用,除非我单击 ImageView 原始位置。

是否有某种方式可以识别动画图像何时被点击

最佳答案

平移动画是一种 View 动画,它只会改变视觉绘制 View 的位置,而不是实际位置。您要么需要切换到使用其中一种属性动画,要么编写自定义 View 动画,专门使用 setX 或 setY 更新 View 的位置。

示例代码:

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

您可以在此处阅读有关 View 动画的更多信息:HERE

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

关于android - 为动画 ImageView 注册 onclick,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25653904/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com