I have an arrow image that I want to rotate from 0 to 180 degree (like the needle in a meter.) One point of the arrow is fixed in middle and at bottom of the screen and head of arrow should move. Length of arrow is fix (it is image). Also I have two buttons and I want arrow to turn left when button left is touched and turn right when right button is touched.
What is the logic of this process?
Drag the dots to the edges of your desired photo or tap Auto. To rotate a photo 90 degrees, tap Rotate . To make minor adjustments to straighten the photo, use the dial above Rotate . To automatically straighten the photo, tap Auto.
In android, Rotate animation is used to change the appearance and behavior of the objects over a particular interval of time. The Rotate animation will provide a better look and feel for our applications.
This is actually pretty simple if you are using a canvas to do your drawing(as you should in your case).
Given that you know the coordinates for the point around which the image should rotate, you can do it like this:
private void doDraw(Canvas canvas) {
canvas.save();
float px = ...;
float py = ...;
canvas.rotate(degrees, px, py);
arrow.draw(canvas);
canvas.restore();
}
degrees will be a integer value that you increment/decrement when the user clicks the L or R buttons. canvas.rotate takes care of the rest!
You have to work with probably animation using 3d rotation in android and try to also usong Matrix Rotation ...I have bitmap code for this.........
Bitmap bmp=BitmapFactory.decodeResource(getResources(), R.drawable.bar);
Matrix mtx = new Matrix();
mtx.postRotate(180); // rotating 180 degrees clockwise
Bitmap rotatedBMP = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth() ,bmp.getHeight() , mtx, true); // creating the bitmap image with new angle
also check this
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/animation/Rotate3dAnimation.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With