johnsonpinto
johnsonpinto

Reputation: 61

rotate image in android imageview

I want to build an application where, I have an image displayed via (ImageView). and a textbox in the application. I want to rotate the image in continuously for about 10 degree for every one second. when the image rotates, the textbox should display the number of times the image is rotated. I tried rotating the image but every time the application crashes or doesn't show up in the screen.

Can someone help me with the code plz ??

Thanks

Upvotes: 0

Views: 3768

Answers (1)

ice
ice

Reputation: 309

Create animation inn res/anim with this code

<rotate
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:toDegrees="360"
    android:pivotX="50%"
    android:pivotY="50%"
    android:repeatCount="infinite"
    android:duration="36000" />

and in your Activity:

Animation rotate = AnimationUtils.loadAnimation(this, R.anim.rotate);
findViewById(R.id.yourImageId).startAnimation(rotate);
rotate.reset();
rotate.start();

Upvotes: 2

Related Questions