Android Recyclerview的Item里的动画 fillAfter(true) 失效问题
PHP中文网
PHP中文网 2017-04-17 17:35:41
0
1
715
public void startTween(final ImageView v, final boolean clicked){
    RotateAnimation rotateAnimation = new RotateAnimation(0, 45,
            Animation.RELATIVE_TO_SELF,0.5f,
            Animation.RELATIVE_TO_SELF,0.5f);
    rotateAnimation.setDuration(1000);
    rotateAnimation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            if (clicked){
                Log.e("test","ic_small");
                v.setImageResource(R.drawable.ic_close_small);

            }else {
                Log.e("test","ic_add");
                v.setImageResource(R.drawable.ic_add);
            }
            Log.e("test","onAnimationEnd");
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });
    rotateAnimation.setFillAfter(true);
    v.setAnimation(rotateAnimation);
    rotateAnimation.start();
}

这是在 Recyclerview的Item里,v是动画的目标对象,是一个Imageview,现在的问题是`setFillAfter(true);`与结束监听里的`v.setImageResource(R.drawable.ic_add);`会出问题,直接回到第一帧,而不是停留在最后一帧,如果把结束监听里的`v.setImageResource(R.drawable.ic_add);`去掉,那么就会停留在最后一帧,我的目的是让其停留在最后一帧,然后用一个与最后一帧一样的图片代替目前的图片资源.

ps:Item里的动画用tween还是属性动画好?谢谢
PHP中文网
PHP中文网

认证0级讲师

reply all(1)
黄舟

To maintain the end state of the view, you must change the attributes of the view, not the attributes of the animation (animation will not help you change the attributes of the View)
rotateAnimation.setFillAfter(true);
rotateAnimation.setFillBefore(false);
you Give it a try and see if it works

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template