Android ValueAnimator onAnimationUpdate doesn't work correctly

1.5k views Asked by At

It doesn't work correctly when I use a property animation. The following is my code. Click a view to perform a toggle animation, but it didn't come to the expected result.The log shows the callback of "onAnimationUpdate" was called only twice and returned the max value.

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

Here is the LOG.

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

There are 1 answers

0
ehart On BEST ANSWER

I solved it finally.The problem is that I just turned off animations on my test device when I did a UI test with espresso a few days ago.Then I turned on the animations and it works now.