Search code examples
androidrotationimage-rotation

Part of Image vanishes when I rotate it in ImageView


I need to rotate an image by some degrees. But when I rotate, its some part vanishes and vanishing increases with degrees and at last, the whole image disappears and appears after the time programmed. What is the problem? I am using the code below to rotate.

        @Override
        public void onClick(View v) {
            AnimationSet animSet = new AnimationSet(true);
            animSet.setInterpolator(new DecelerateInterpolator());
            animSet.setFillAfter(true);
            animSet.setFillEnabled(true);

            final RotateAnimation animRotate = new RotateAnimation(0.0f, 155.0f,
                RotateAnimation.RELATIVE_TO_SELF, 0.5f, 
                RotateAnimation.RELATIVE_TO_SELF, 0.5f);

            animRotate.setDuration(5000);
            animRotate.setFillAfter(true);
            animSet.addAnimation(animRotate);

            myImageView.startAnimation(animSet);
        }
    });

Solution

  • This could be related to https://code.google.com/p/android/issues/detail?id=70914 Corrupted rotations on certain devices (mostly Nexus 5) You may want to try setting the layer type to hardware or software.

    view.setLayerType(View.LAYER_TYPE_HARDWARE, null);