在Android中制作动画后使视图可单击
动画完成后,我无法单击“视图”。我对此进行了大量搜索,阅读了stackoverflow的答案,发现了一些动画只绘制原始像素的东西。要使视图可单击,必须移动视图。所以我写了一些代码,但效果不好。在Android中制作动画后使视图可单击,android,android-animation,Android,Android Animation,动画完成后,我无法单击“视图”。我对此进行了大量搜索,阅读了stackoverflow的答案,发现了一些动画只绘制原始像素的东西。要使视图可单击,必须移动视图。所以我写了一些代码,但效果不好。 这是我的密码 anim.xml <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/linear_interpolator" android:fillA
这是我的密码 anim.xml
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fillAfter="true">
<translate
android:fromXDelta="0%p"
android:toXDelta="-50%p"
android:duration="500" />
此代码的问题是,在运行onAnimationEnd后,动画的位置发生了变化。为什么会发生这种情况。我认为一旦动画完成,它将进一步移动,对吗?请让我知道我遗漏了什么。你能解释一下你的问题吗?最后两行让我很困惑。@RachitSolanki我编辑了我的问题,你能检查一下吗again@RachitSolanki我只想在动画后使
imageView
可单击。如果我错了,请纠正我,但在动画结束后,您的imageView位置改变,但不是可单击区域。我是否正确?是的,这就是我尝试更改动画移动的imageview位置的方式。
Animation anim= AnimationUtils.loadAnimation(this, R.anim.anim);
anim.setAnimationListener(animLintener);
imageView.startAnimation(anim);
private Animation.AnimationListener animLintener= new Animation.AnimationListener() {
@Override
public void onAnimationEnd(Animation animation) {
int widthHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 30, context.getResources().getDisplayMetrics());
int marginBottom = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 36, context.getResources().getDisplayMetrics());
int marginLeft = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 36, context.getResources().getDisplayMetrics());
deactivateParams = new RelativeLayout.LayoutParams(widthHeight, widthHeight);
deactivateParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
deactivateParams.bottomMargin = marginBottom;
deactivateParams.leftMargin = marginLeft;
imageView.setLayoutParams(deactivateParams);
}
}