I need to rotate the linearlayout with it's child view's. Now I am using android 2.2 but in Android 3.0 has a rotate option.If we set the rotation degree we can get the rotated view.
setRotation(float rotation)
I need to rotate my view by using android 2.2. How to do this in android 2.2 .Can any one suggest me to do .... !!
Note: I need to rotate the view relevant to it's touch position
Try this:
Create this drawable, say rotation.xml:
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:interpolator="#android:anim/linear_interpolator"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000"
android:startOffset="0"
/>
Now set this drawable in the android:src tag of your view.
Related
I have an ImageView that should rotate for 4 times. This is my xml of animation:
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:fromDegrees="0"
android:interpolator="#android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="3"
android:repeatMode="restart"
android:toDegrees="360" />
but rotation is not fluid: there's a little delay from end of a rotation, and begin of next one. How can i fix it?
Try to rotate from 0 to 359. 0 and 360 is the same in that context.
why not create an animation the usual way, and if you want it to rotate four times, then create a loop that iterates four times, and for each iteration, it calls the animation. You have to optimize your code so that are no visible drags.
i am developing app, in which i want am image to move along a curve path in the background screen.i am able to move the image from one point to another using the below translate xml, but its moving along a straight path, i want it to move along a curve path.how can i achieve this?
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="3000"
android:fromXDelta="-20%"
android:fromYDelta="-10%"
android:toXDelta="150%"
android:toYDelta="-130%"
android:zAdjustment="normal" />
please help.thanks!
<rotate
android:toDegrees="360"
android:pivotX="100%"
android:pivotY="200%"
android:duration="6000"
android:repeatMode="restart"
android:repeatCount="infinite"/>
Workaround: I used rotate and played with pivotX and pivotY and image position
I have a transition from one activity to another that I am using in overridePendingTransition. Unfortunately all overridePendingTransition uses is the resource id of the file, so I am having trouble about how to edit this file so my transitions are proper.
Basically what I need to do is make changes to the R.anim.flip_in_scale_in so that I can change the value of the transitions fromX/toX so that it is set based on the user's screen size.
overridePendingTransition(R.anim.flip_in_scale_in, R.anim.stationary_item);
How do I update the R.anim.flip_in_scale_in file before use in the overridePendingTransition?
There isn't a way you can alter the animation from the resource file in the way you want.
However, you CAN create the animation to use percentages rather than dp values. When the animation is applied to the Activity's View, it will animate entirely on the view's size (which in most cases is the screen size).
This for example:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="100%"
android:toXDelta="0%"
android:duration="500"
/>
</set>
Will slide in the view from the right side to the screen within half-a-second.
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:interpolator="#android:anim/accelerate_decelerate_interpolator"
android:fromXScale="1.0"
android:toXScale="1.4"
android:fromYScale="1.0"
android:toYScale="1.4"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000" />
</set>
This will increase the view to 40% it's current size over the span of one second. The pivot will be directly in the middle of the view regardless of the view's size.
I am new to android development, can any one tell me how to rotate entire a button into 45 degrees along with text and button rect. I want to rotate permanently and i want on click listener on the same.
You need to use animations for that.
in your /res/anim/ you must create an xml file with this:
<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="45"
android:pivotX="50%"
android:pivotY="50%"
android:duration="0"
android:startOffset="0"
/>
and the in your Activity:
RotateAnimation ranim = (RotateAnimation)AnimationUtils.loadAnimation(this, R.anim.YOUR_ANIM);
ranim.setFillAfter(true);
YourButton.setAnimation(ranim);
Apart from that it seems that there are some problems with diagonal rotations (a.k.a. 45 degrees) pre-honeycomb..
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.