在保留比例动画的同时应用摇动动画 [英] Applying shake animation while retaining the scale animation

查看:61
本文介绍了在保留比例动画的同时应用摇动动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在RecyclerView上应用比例动画.我将此动画应用于OnFocusChangeListener事件.应用此动画后,我还想将一个震动动画应用于相同的项目,同时保留先前的比例.

I am applying a scale animation on RecyclerView. I am applying this animation on OnFocusChangeListener event. After this animation is applied, I also want to apply a shake animation to the same item while it retains the previous scale.

但是在我的情况下,在应用震动动画之前,该项目会缩放到正常大小.

but in my case the item is scaled back to normal size before applying the shake animation.

这是我面临的问题.

缩放动画zoom_in.xml

scale animation zoom_in.xml

<?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>

摇动动画shake.xml

Shake animation shake.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="100"
        android:fromXDelta="-5%"
        android:repeatCount="3"
        android:repeatMode="reverse"
        android:toXDelta="5%" />
</set>

OnFocusChangeListener-这是我缩放对象的地方

OnFocusChangeListener - This is where I scale the object

holder.channelCardView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View view, boolean hasFocus) {
                if (hasFocus) {

                    Animation animZoomIn = AnimationUtils.loadAnimation(mContext, R.anim.zoom_in);
                    view.startAnimation(animZoomIn);
                } else {
                    Animation animZoomOut = AnimationUtils.loadAnimation(mContext, R.anim.zoom_out);
                    view.startAnimation(animZoomOut);
                }
            }
        });

OnKeyListener-这是我应用震动动画的地方.

OnKeyListener - This is where I apply shake animation.

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

我想在缩放项目时应用震动动画,并希望保持缩放直到焦点改变.

I want to apply the shake animation while the item is zoomed and I want to keep it zoomed until focus is changed.

感谢您的帮助

推荐答案

大量阅读后,我自己找到了解决方案.通过如下更改shake.xml即可解决问题.

After lot of reading I found the solution myself. by changing the shake.xml as below the problem is solved.

<?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>

这篇关于在保留比例动画的同时应用摇动动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆