How to tilt a button along with its text...? - android

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..

Related

How does pivotX/Y work in a rotate animation set

I am trying to understand how rotate animation works.
With the following I rotate a view as follows:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="8000"
>
<rotate android:fromDegrees="0"
android:toDegrees="30"
android:pivotX="100%"
android:pivotY="100%"
/>
<rotate
android:toDegrees="100"
android:pivotX="100%"
android:pivotY="30%"
/>
</set>
Result:
Now where the arrow is I am trying to rotate again using that as a center.
So I modified my animation set as follows:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="8000">
<rotate android:fromDegrees="0"
android:toDegrees="30"
android:pivotX="100%"
android:pivotY="100%"
/>
<rotate
android:toDegrees="100"
android:pivotX="100%"
android:pivotY="30%"
/>
<rotate android:pivotY="-30%"
android:pivotX="40%"
android:toDegrees="100"/>
</set>
I.e. I added
<rotate android:pivotY="-30%"
android:pivotX="40%"
android:toDegrees="100"/>
This seems correct to me because looking at the screen the rotate point is around 30% less than the left most value of y and x is about 40% more than the left most value of x.
But when the animation runs it is not working as expected. To be honest I have no clue what is the actual rotation point and the whole view skews to the left.
Result:
What am I misunderstanding here?
Pivot is the point around which it rotates (like putting a pin in a photo). If your 'from' and 'to' pivots aren't the same then you are not just rotating around a set point, you're rotating a bit, then changing the pins location and rotating a bit more for each step (causing a skew).
Just in case you don't know: Android coordinates start at top left not bottom left.
I think all you want in that set is
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="8000">
<rotate android:fromDegrees="0"
android:toDegrees="130"
android:pivotX="100%"
android:pivotY="30%" />
<!-- I believe this, below will the the correct slide you need -->
<translate android:fromXDelta="0"
android:toXDelta="-100%" />
</set>
Which will rotate it 130 degrees around the pin at [100%, 30%] (x being the maximum value , i.e right edge of the screen, and y being 30% of the way down the screen) and at the same time slide it right until it's 100% (of view width) to the right of it's starting position

can only perform rotation of image view without holding it

Hi guys i uses the code below to perform rotation but it only rotates one time and goes back to its original position, how to let the image stay at the rotated position?
<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="90"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000"
android:startOffset="0"
/>
xml file of my code
Animation rotation = AnimationUtils.loadAnimation(this, R.anim.rotate);
a.startAnimation(rotation);
use:
anim.setFillAfter(true);
If fillAfter is true, the transformation that this animation performed
will persist when it is finished. Defaults to false if not set. Note
that this applies to individual animations and when using an
AnimationSet to chain animations.

android rotate animation, make it fluid

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.

Image moving in background along a curve path android

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

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