Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotating a view in Android

I have a button that I want to put on a 45 degree angle. For some reason I can't get this to work.

Can someone please provide the code to accomplish this?

like image 262
Matthew Avatar asked Dec 18 '09 22:12

Matthew


People also ask

How do you flip a view on Android?

You can flip a layout by setting the View property scaleX to -1. So View#setScaleX(1f) is normal, and View#setScaleX(-1f) is flipped (visually). To do it pre-Honeycomb, you can use scale properties in the general Animation library.

How do I manually rotate my Android screen?

1 Swipe down the screen to access your Quick Settings and tap on Auto Rotate, Portrait or Landscape to change your screen rotation settings. 2 By selecting Auto Rotate,you will easily be able to switch between Portrait and Landscape mode. 3 If you choose Portrait this will lock the screen from rotating to landscape.


2 Answers

API 11 added a setRotation() method to all views.

like image 105
Jens Zalzala Avatar answered Sep 22 '22 15:09

Jens Zalzala


You could create an animation and apply it to your button view. For example:

    // Locate view     ImageView diskView = (ImageView) findViewById(R.id.imageView3);      // Create an animation instance     Animation an = new RotateAnimation(0.0f, 360.0f, pivotX, pivotY);      // Set the animation's parameters     an.setDuration(10000);               // duration in ms     an.setRepeatCount(0);                // -1 = infinite repeated     an.setRepeatMode(Animation.REVERSE); // reverses each repeat     an.setFillAfter(true);               // keep rotation after animation      // Aply animation to image view     diskView.setAnimation(an); 
like image 38
Pete Avatar answered Sep 20 '22 15:09

Pete