android ValueAnimator属性动画 onAnimationUpdate回调异常?
巴扎黑
巴扎黑 2017-04-17 15:36:28
0
2
843

使用属性动画遇到异常以下是我的代码,点击一个View然后这个View执行一个高度变化的动画。但是动画没有按照预期出现。加上LOG以后发现动画的回调只调了两次,而且返回的值是最大值。各路大神求解!

 @Override
 public void onClick(View v) {
     switch (v.getId()) {
        case R.id.product_item_top_rl: 
        startAnimation(v);
        break;
     }
 }
 
private void startAnimation(final View v) {
    int height = v.getHeight();
    ValueAnimator va = ValueAnimator.ofInt(0, height);
    va.setDuration(1000);
    va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        public void onAnimationUpdate(ValueAnimator animation) {
            Log.d(TAG, "animation : " + animation.getAnimatedValue());
            v.getLayoutParams().height = (Integer) animation.getAnimatedValue();
            v.requestLayout();
        }
    });
    va.start();
}

D/ChooseProductFragment: animation : 150
D/ChooseProductFragment: animation : 150

巴扎黑
巴扎黑

reply all(2)
Peter_Zhu

Problem solved. It's because yesterday, in order to use espresso for UI automation testing, I turned off the three animations "Window Animation Scaling", "Excessive Animation Scaling", and "Animation Program Duration Adjustment" in the settings. Re-enable these animations and it will be normal.

迷茫

You did not specify the number and method of looping the animation, you should add

//无限循环
va.setRepeatCount(ValueAnimator.INFINITE);
//从头开始动画
va.setRepeatMode(ValueAnimator.RESTART);
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!