rotate image in android imageview - android

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

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();

Related

How to create an animation in a splash screen?

When we open a app we get different type of animated object or people moving around in the splash screen of an app for example like a person running while the app is loaded or the name of the app falls and a guy sits on it clicking photos.
How can we create one and what type of software do we use?
Can you suggest me some tutorials to follow?
use gif
OR
use Animation :
Ex) Awesome-looking customizable splash screen : AwesomeSplash
paste this xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/bounce_interpolator" >
<scale
android:duration="600"
android:fromXScale="1"
android:fromYScale="0.5"
android:pivotX="50%"
android:pivotY="0%"
android:toXScale="1.0"
android:toYScale="1.0" />
<alpha
android:duration="600"
android:fromAlpha="0.0"
android:toAlpha="1.0" />
</set>
and on the splash screen
Animation animation = AnimationUtils.loadAnimation(contex, R.anim.blink);
animation.setInterpolator(new LinearInterpolator());
animation.setRepeatCount(Animation.INFINITE);
animation.setDuration(700);
and use this Animation like
final ImageView splash = (ImageView) findViewById(R.id.btnrecievecall);
splash.startAnimation(animation)
You can also use your own created gif images to show on the imageview at splash screen through Glide image loading and caching library.
Like :
ImageView imageView = (ImageView) findViewById(R.id.imageView);
GlideDrawableImageViewTarget imageViewTarget = new GlideDrawableImageViewTarget(imageView);
Glide.with(this).load(R.raw.gif_image).into(imageViewTarget);
1.. use gif file
or
2.. First using set animation effect, and after direct using this image splace screen.

How do I animate, Moving an ImageView on a circular path with certain radius in android?

Please Find the attachment for my image.
https://docs.google.com/file/d/0B_c-SDSO63obS0ZyQ1dsOXdUQmc/edit?usp=sharing
My task is, animate that GONG type of image up to some time with clock wise and anti clock wise.
For that i did some coding in animation but i didn't succeed. I am using both translate and rotate.
<translate
android:fromXDelta="0%p"
android:toXDelta="75%p"
android:duration="1500" />
and rotate functions,
<rotate android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="600"
android:repeatMode="restart"
android:repeatCount="infinite"
android:interpolator="#android:anim/cycle_interpolator"/>
Actually my idea is in a specific time i want to move with specific angle. But i don't know the correct way to solve this task.
Please help me. sorry for my English.
All answers are acceptable
Thanks
Shankar
You have divided a circle in 12 parts in that image and that equals to 30 degrees per segment.
you have to rotate it like this to look proper
rotateDegree=[steps]*30;
use AlarmManager to trigger animation in specific time
EDIT:
to move your image in circular path with a radius you have to give a different pivot x and y
you can find it by tryng with
pivotX= 0 and pivotY=(negative value)
I hope this helps.

Rotating image in Imageview overlaps corners

I am using following 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
Animation rotate = AnimationUtils.loadAnimation(this, R.anim.rotate);
findViewById(R.id.yourImageId).startAnimation(rotate);
rotate.reset();
rotate.start();
The intention was to rotate the image inside the Imageview.
Because this image view has a background colour, this appears to rotate the whole ImageView control and it starts to overlap the text view placed next to it, for example after 45 degree rotation one corner would be overlapping the view placed to left of it
I want to show that the container is not spinning, rather just the image.
I can not remove the background, this will disturb the UI feel in my particular case.
Is it a good idea to place this into a Layout and remove background from this imageview and spin ? or is there a smarter way to it.
You could overlap 2 views (one only with the background and the other with your image) and set the Animation to rotate only the view with the image.
Regards.

Rotation of image using ViewAnimation or PropertyAnimation in android

I want to rotate an image in my application in such a manner that it rotate like a simple pendulam and will stop after some time.
How I can achieve it using View Animation or Property Animation in android
I used the below xml for the animation
<rotate
android:duration="2000"
android:interpolator="#android:anim/accelerate_decelerate_interpolator"
android:fromDegrees="-15"
android:pivotX="50%"
android:pivotY="0%"
android:repeatCount="5"
android:repeatMode="reverse"
android:toDegrees="15" />
And below is the code for the animation
Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(this,
R.anim.rotate);
firstBell.startAnimation(hyperspaceJumpAnimation);
But the problem is when animation starts it suddenly move to angle -15 and then start animating. And it stops after 5 count suddenly not in smooth way.
So my question is how to resolve this issue
Looking for help.
About -15 degree:
android:fromDegrees="-15"
and
android:toDegrees="15"
These two lines mean your object start from -15 degrees and end with 15 degree. If that are not what you want, just delete them.
For the Smooth way, you may find the fade.xml in your ApiDemo/res/anim folder.

Rotating A Dial in Android

I need to rotate my image in my on touch listener when the user touches it. I am rotating a dial graphic, so it needs to rotate around its center point. Does anyone have an example?
I'd refer to the actual android documentation for animation here: http://developer.android.com/guide/topics/resources/animation-resource.html
As for setting up the rotation in an xml, it will look something like:
<set android:interpolator="#anim/linear_interpolator">
<rotate
android:fromDegrees="180"
android:toDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="0"
android:duration="1000">
</rotate>
</set>
That is for a 180 rotation.

Categories

Resources