Search code examples
androidviewadmobandroid-animationandroid-custom-view

ValueAnimator behaviour changes when AdView shows in


I've made a custom view for visualizes the progress. It has a simple intro animation like the below :

PropertyValuesHolder c=PropertyValuesHolder.ofInt("c",0,100);
ValueAnimator anim=new ValueAnimator();
anim.setValues(c);
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
      @Override
      public void onAnimationUpdate(ValueAnimator animation) {
          position = (int) animation.getAnimatedValue("c");
          postInvalidate();
      }
  });
anim.setDuration(1000);
anim.start();

It works smoothly with about 50 keyframes, but after the AdView that placed on the parent view, turns visible the same animation runs with lags (performance reduced to about 20 keyframes). I check the ValueAnimator.FrameDelay, it doesn't change.

before adMob after adMob

What causes this problem, And what is the solution?


Solution

  • As @MartinMarconcini said, the problem related to the WebView that embedded inside the AdView. The performance improved by enabling Hardware Acceleration on the AdView.

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) 
            adView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
       else adView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);