How to make Rotate3dAnimation more smoother?

前端 未结 4 899
北荒
北荒 2020-12-30 06:47

In my app I am using Rotate3dAnimation to show a Google map. The code is working fine, but the animation is not smooth, some lines are also visible while rotating the view.

4条回答
  •  被撕碎了的回忆
    2020-12-30 07:16

    I will just give a small hint; however right now I am so busy at work I can not implement this.

    The steps are

    • get your drawing cache Bitmap
    • set your content to an imageview only with this Bitmap
    • apply the animation to this imageview
    • at the end of the animation re set your content

    This I believe will maximize the performance.

    I will try to write some code later.

    CODE

    View longLivingReference; //keep a reference
    private void applyRotation(int position, float start, float end) {
        longLivingReference = findViewById(R.id.event_container);
        longLivingReference .setDrawingCacheEnabled(true);
        Bitmap bitmapForAnimation = Bitmap.createBitmap(longLivingReference.getDrawingCache());
        ImageView iv = new ImageView(mContext);
        iv = new ImageView(mContext);
        iv.setImageBitmap(bitmapForAnimation);
        setContentView(iv);
    
        final float centerX = mContainer.getWidth() / 2.0f;
        final float centerY = mContainer.getHeight() / 2.0f;
        final Rotate3dAnimation rotation = new Rotate3dAnimation(start, end, centerX, centerY, 310.0f, true);
        rotation.setDuration(500);
        rotation.setFillAfter(true);
        rotation.setInterpolator(new AccelerateInterpolator());
        rotation.setAnimationListener(yourAnimationListener {
            //whatever your AnimationListener is, you can call super.onAnimationEnd if needed
            @Override
            public void onAnimationEnd(Animation animation) {
                setContentView(longLivingReference);
            }
        });
        iv.startAnimation(rotation);
    }
    

提交回复
热议问题