Search code examples
androidandroid-layoutrotationandroid-relativelayout

Rotating a Relative Layout without using any animation stuff


Is there a way to set the duration of rotation without using animation stuff, because those stuff causes some other stuff.

relative = (RelativeLayout) findViewById(R.id.relative);
relative.setOnTouchListener(new View.OnTouchListener() {
    @Override
        public boolean onTouch(View v, MotionEvent event) {
            relative.setRotation(relative.getRotation() + 90);
            return true;
        }
    });

Just smooth rotation and nothing more!


Solution

  • You literally can't have a smooth rotation without animating it. But, it doesn't have to be difficult. This will rotate your view by an additional 90 degrees over 300 milliseconds, and be nice and smooth:

    relativeLayout.animate().rotationBy(90).setDuration(300).start();