动画期间点击查看没有反应
Click on view during animation doesn't react
我有一个简单的动画:
<rotate android:fromDegrees="0"
android:toDegrees="180"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="4"
android:repeatMode="reverse"
android:duration="1000"
android:interpolator="@android:anim/linear_interpolator" />
<translate
android:duration="2000"
android:fromXDelta="10%p"
android:toXDelta="90%p"
android:repeatCount="1"
android:repeatMode="reverse"
android:fillAfter="true"/>
我 运行 它在 ImageView
上。我在 ImageView
:
上设置了一个 onclick 事件
imgCorrect1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d(TAG, "explode ");
}
});
这是我开始动画的方式:
Animation anim = AnimationUtils.loadAnimation(this, R.anim.rottrans);
imgCorrect1.startAnimation(Anim1);
问题是,在动画播放时,如果我在动画播放时点击图像,则在动画播放 运行ning 时不会调用 onclick。
我曾尝试搜索此问题,但所有帖子都是为了动画化 ImageView
- 当 - onclick 被调用时,而不是相反。
我希望我在此处的描述中已经清楚了。我已尝试提供所有相关代码来解释该问题。
您正在使用 Animation
API,它为视图矩阵设置动画。因此,您会看到原始视图的 ghost 正在动画化,而视图仍位于原始位置。
而是使用 Animator API。它可能是这样的:
ImageView imageView = ...;
ObjectAnimator rotate = ObjectAnimator.ofFloat(imageView, View.ROTATION, 0, 180);
rotate.setRepeatCount(4);
rotate.setRepeatMode(ValueAnimator.REVERSE);
rotate.setDuration(1000);
rotate.setInterpolator(new LinearInterpolator());
ObjectAnimator translate = ObjectAnimator.ofFloat(imageView, View.TRANSLATION_X, 0, 100);
translate.setRepeatCount(1);
translate.setRepeatMode(ValueAnimator.REVERSE);
translate.setDuration(2000);
AnimatorSet set = new AnimatorSet();
// Play either sequentially or together
set.playSequentially(rotate, translate);
// set.playTogether(rotate, translate);
set.start();
我有一个简单的动画:
<rotate android:fromDegrees="0"
android:toDegrees="180"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="4"
android:repeatMode="reverse"
android:duration="1000"
android:interpolator="@android:anim/linear_interpolator" />
<translate
android:duration="2000"
android:fromXDelta="10%p"
android:toXDelta="90%p"
android:repeatCount="1"
android:repeatMode="reverse"
android:fillAfter="true"/>
我 运行 它在 ImageView
上。我在 ImageView
:
imgCorrect1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d(TAG, "explode ");
}
});
这是我开始动画的方式:
Animation anim = AnimationUtils.loadAnimation(this, R.anim.rottrans);
imgCorrect1.startAnimation(Anim1);
问题是,在动画播放时,如果我在动画播放时点击图像,则在动画播放 运行ning 时不会调用 onclick。
我曾尝试搜索此问题,但所有帖子都是为了动画化 ImageView
- 当 - onclick 被调用时,而不是相反。
我希望我在此处的描述中已经清楚了。我已尝试提供所有相关代码来解释该问题。
您正在使用 Animation
API,它为视图矩阵设置动画。因此,您会看到原始视图的 ghost 正在动画化,而视图仍位于原始位置。
而是使用 Animator API。它可能是这样的:
ImageView imageView = ...;
ObjectAnimator rotate = ObjectAnimator.ofFloat(imageView, View.ROTATION, 0, 180);
rotate.setRepeatCount(4);
rotate.setRepeatMode(ValueAnimator.REVERSE);
rotate.setDuration(1000);
rotate.setInterpolator(new LinearInterpolator());
ObjectAnimator translate = ObjectAnimator.ofFloat(imageView, View.TRANSLATION_X, 0, 100);
translate.setRepeatCount(1);
translate.setRepeatMode(ValueAnimator.REVERSE);
translate.setDuration(2000);
AnimatorSet set = new AnimatorSet();
// Play either sequentially or together
set.playSequentially(rotate, translate);
// set.playTogether(rotate, translate);
set.start();