Koen027
Koen027

Reputation: 863

Putting a timer on image rotation?

On Android(2.3.3), is it possible to make the rotation of an image not be instant?

The code example I used, from here:

img=(ImageView)findViewById(R.id.ImageView01);
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.refresh);
// Getting width & height of the given image.
int w = bmp.getWidth();
int h = bmp.getHeight();
// Setting post rotate to 90
Matrix mtx = new Matrix();
mtx.postRotate(90);
// Rotating Bitmap
Bitmap rotatedBMP = Bitmap.createBitmap(bmp, 0, 0, w, h, mtx, true);
BitmapDrawable bmd = new BitmapDrawable(rotatedBMP);

img.setImageDrawable(bmd);

This rotation is instant, and I'd like to make the rotation visible. Is that possible in Android, or is that a Flash thing?

Upvotes: 1

Views: 1113

Answers (3)

span
span

Reputation: 5624

If you want a delay before your image rotates you can check out AlarmManager. This should not be used to delay any animation as stated below in the comments by David Caunt.

If you want to animate the rotation you can check out RotateAnimation http://developer.android.com/reference/android/view/animation/RotateAnimation.html

Here is an example of rotating a text view, perhaps it can be helpful. http://www.edumobile.org/android/android-programming-tutorials/rotating-text-animation/

Upvotes: 1

Jave
Jave

Reputation: 31846

You should use a ViewAnimation on your imageview. Something like this is what you need:

in your res/anim folder:

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android" 
    android:fromDegrees="0" android:toDegrees="90"
    android:duration="2000" android:interpolator="@android:anim/accelerate_decelerate_interpolator"
    android:startOffset="1000"
/>

Apply it to your view:

img.startAnimation(AnimationUtils.loadAnimation(context, R.anim.rotate));

You'll have to explore the different options and attributes on your own :)
Here's a link to some more info.

Upvotes: 3

dinesh707
dinesh707

Reputation: 12592

What you can do is call the same code again and rotating the image by 1 degree angle. By using the above method you really cant do any other way. But again if you try to trigger 1 degree by 1 degree at a rate of 25 frames per second it will not run smoothly in a tablet or mobile phone. You can try animations provided from android. But they apply animations for whole screen (as far as i know).

Upvotes: 0

Related Questions