Android 在保留缩放动画的同时应用抖动动画
我正在RecyclerView上应用缩放动画。我正在OnFocusChangeListener事件上应用此动画。应用此动画后,我还希望对相同的项目应用一个抖动动画,同时它保留以前的比例 但在我的例子中,在应用抖动动画之前,该项目会缩小到正常大小 这就是我面临的问题。 缩放动画zoom_in.xmlAndroid 在保留缩放动画的同时应用抖动动画,android,android-animation,Android,Android Animation,我正在RecyclerView上应用缩放动画。我正在OnFocusChangeListener事件上应用此动画。应用此动画后,我还希望对相同的项目应用一个抖动动画,同时它保留以前的比例 但在我的例子中,在应用抖动动画之前,该项目会缩小到正常大小 这就是我面临的问题。 缩放动画zoom_in.xml <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:fillEnabled="true"
android:interpolator="@android:anim/linear_interpolator"
android:zAdjustment="top">
<scale
android:duration="200"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.2"
android:toYScale="1.2" />
</set>
OnKeyListener-这是我应用抖动动画的地方
holder.channelCardView.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_DPAD_RIGHT && getItemCount() == position + 1) {
if(getItemCount() == position + 1 && count[0] >= 2) {
Animation animShake = AnimationUtils.loadAnimation(mContext, R.anim.shake);
holder.channelCardView.startAnimation(animShake);
}
else {
count[0]++;
}
}
else {
count[0] = 0;
}
return false;
}
});
我希望在缩放项目时应用抖动动画,并希望在更改焦点之前保持其缩放
感谢您的帮助经过大量阅读,我自己找到了解决方案。通过如下更改shake.xml,问题得以解决
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fillEnabled="true"
android:fillAfter="true">
<scale
android:duration="200"
android:fromXScale="1.2"
android:fromYScale="1.2"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.2"
android:toYScale="1.2" />
<translate
android:duration="100"
android:fromXDelta="-3%"
android:repeatCount="3"
android:repeatMode="restart"
android:toXDelta="3%" />
</set>
我在shake.xml文件中使用了fillBefore=“false”属性。fillBefore属性做什么?任何人?我仍然无法解决这个问题。我找到了一个解决方案,请看下面我的答案
holder.channelCardView.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_DPAD_RIGHT && getItemCount() == position + 1) {
if(getItemCount() == position + 1 && count[0] >= 2) {
Animation animShake = AnimationUtils.loadAnimation(mContext, R.anim.shake);
holder.channelCardView.startAnimation(animShake);
}
else {
count[0]++;
}
}
else {
count[0] = 0;
}
return false;
}
});
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fillEnabled="true"
android:fillAfter="true">
<scale
android:duration="200"
android:fromXScale="1.2"
android:fromYScale="1.2"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.2"
android:toYScale="1.2" />
<translate
android:duration="100"
android:fromXDelta="-3%"
android:repeatCount="3"
android:repeatMode="restart"
android:toXDelta="3%" />
</set>