Rotate button about X-axis in an Android app - android

I want to rotate a button about X-axis when clicked and then display a different image so it creates an effect that after button click it's flipping and showing a different image which is at its backside.
I'm using following xml for rotation of button:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<set android:interpolator="#android:anim/decelerate_interpolator">
<rotate
android:fromDegrees="0"
android:toDegrees="-360"
android:pivotX="25%"
android:pivotY="25%"
android:fromXDelta="0"
android:toXDelta="0"
android:fromYDelta="0"
android:toYDelta="0"
android:duration="400" />
</set>
</set>
But it's rotating the button in 2-D plane about the button's center.

I have a flip example here:
http://www.inter-fuser.com/2009/08/android-animations-3d-flip.html

I'm afraid the conventional graphics and animation APIs are 2D. To use that 3rd dimension you'd need to look into OpenGL, which is non-trivial.
You might be able to fake a depth effect by writing a custom animation that uses setPolyToPoly to warp your initial rect into a trapezoid.

It's been a while since this question is posted, but just for the record - there is a way in newer versions of android, and for back compatibility use http://nineoldandroids.com/

Related

Android triangle fadein animation

I have the following animation:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="100%" android:toYDelta="0%" android:duration="1000" />
<translate android:fromXDelta="80%" android:toXDelta="0%" android:duration="1000" />
</set>
I use this to animate a new view to is showing up. This animation run from bottom to top and from right to left, but the animation is like rectangle. And i wana make it to be like a triangle
In other words i want the two points (X and Y) that makes the animation to be linked by a straight line.
(Not enough rep to comment)
Is it important for it to be clickable as a triangle? What I mean is, couldn't you just load on the view a triangle-like Drawable image(there are many free icon packs around or you can create your own as .png)?
This way you SEE the triangle, while as an object is just a rectangle with a texture of a triangle. (As I don't think there is any implementation in AndroidSDK of a TriangularView, but I might be wrong!).
Another way is to use a shape drawable resource.
An easy example is how it was done by Sanket Kachhela in this post
https://stackoverflow.com/a/22043386/4482734
You could take it as a starting point.
Then again, much of this post was based on the idea you needed to interact with the Triangle, but I could be wrong and it has no meaning to do so.

Android Translation animation

i am trying to animate an image view by ensuring that the object appears in the center of the screen and then translates up.. to its final position. the code i used is as follows.
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:fromYDelta="400"
android:toYDelta="0"
android:duration="800"/>
</set>
This code works when u have a device of 4.7"(galaxy s3) screen size the image will appear at the center of the screen and then move to its set position. But on a screen of 4" (S advance or htc desire x) the image practically appears at the screen bottom.
So is there any way to ensure that the image is at the center of the screen heedless of the device on which the code is running?? Thanks in advance..
Use percentages instead of values to make the Animation uniform across all screen sizes.
The animation should apply its transformation after it ends
android:fillAfter="true"
The animation begins from the vertical center, i.e 50% of Y
android:fromYDelta="50%p"
The animation ends at the top, i.e. 0% of Y
android:toYDelta="0%p"
XML:
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="800"
android:fillAfter="true"
android:fromYDelta="50%p"
android:toYDelta="0%p" />
</set>
thanks for ur response..
i tried ur suggestion 's and i found that using 50%p to then in a 4 inch screen the image view is present at around 3\4of the screen. but when i use 25%p then its around the center. in case of s advance its center and in s3 its relatively center.. i guess it depends on the size of the image.(dimention)

Animations to make things go around the screen (Android)

I'm new to Android developing. I want some animations when clicking on the card and it will move around the screen and stay at its new position forever (its interactive area should change too).
At first the card is located at the center-bottom of the screen (XDelta= 50% YDelta = 70%) then it will move up straight to center of the screen (XDelta =50% and YDelta is 40%). Then it will move to its upper left (10 dp from the left of the screen and 10 dp from the top of the screen) Sorry I can't post images due to my lack of reputation.
And here's my code in res/anim/card1.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="200"
android:fromXDelta="50%"
android:fromYDelta="70%"
android:toYDelta="40%"
android:toXDelta="50%"
android:fillEnabled="true"/>
<translate
android:duration="100"
android:fillEnabled="true"
android:fromXDelta="50%"
android:fromYDelta="40%"
android:startOffset="200"
android:toXDelta="10"
android:toYDelta="10" />
</set>
And code to get it work when clicking on the card
Animation anim = AnimationUtils.loadAnimation(MainActivity.this,
R.anim.card1);
iv_card.startAnimation(anim);
... but it just don't animate the way I want. Please help me!!!!
Check Out this (http://www.tktutorials.com/2013/07/animation-in-android-using-xml-files.html) this may help your need. Alter the translate.xml file as per your need, which is located in Res->anim->translate.xml
And solution for your posting Image. My suggestion is upload your pic in googleDrive, then change the share setting for the particular pic from private to Public on web and use the url Link to your question.

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

Showing both sides of a coin being flipped using Android standard animation

I'm very close to getting a "coin flipping" animation to work, but due to the limitations (bugs?) in the current Animation system - I cannot find a way to show BOTH sides of a coin flipping in the air.
For example, I have the following Animation .XML:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<scale
android:repeatCount="17"
android:repeatMode="reverse"
android:interpolator="#android:anim/accelerate_decelerate_interpolator"
android:fromXScale="1.0" android:toXScale="1.0"
android:fromYScale="1.0" android:toYScale="0.0"
android:pivotX="50%" android:pivotY="50%"
android:fillEnabled="true"
android:fillAfter="true"
android:duration="60"
/>
<scale
android:repeatCount="1"
android:repeatMode="reverse"
android:interpolator="#android:anim/accelerate_decelerate_interpolator"
android:fromXScale="1.0" android:toXScale="2.0"
android:fromYScale="1.0" android:toYScale="2.0"
android:pivotX="50%" android:pivotY="50%"
android:fillEnabled="true"
android:fillAfter="true"
android:duration="800"
/>
<translate
android:repeatCount="1"
android:repeatMode="reverse"
android:interpolator="#android:anim/accelerate_decelerate_interpolator"
android:fromXDelta="0%"
android:toXDelta="0%"
android:fromYDelta="0%"
android:toYDelta="-150%"
android:fillEnabled="true"
android:fillAfter="true"
android:duration="800"
/>
</set>
This "fakes" a flipping animation by scaling the coin on the Y-axis and reversing it on a loop. In combination to this, there's a scale to make the overall animation bigger, while also translating it up and down. But it is only ever gonna show the one side of the coin.
I tried having two of these animations, each side of the coin, running at the same time, but I cannot find a way to stagger them due to the REPEATCOUNT not working when applied to an AnimationSet. Otherwise I could introduce some kind of delay after one anim (and before the other one) so they alternate, giving the illusion of a coin flipping.
Does anyone know any way I can tweak this to get the desired result?
I had thought of giving up and doing a frame-based anim (pre-render the flip as frames), but it appears you can't mix Frame & Tween anims, so I'd lose the flip "height" and "distance" effects.
(I have another issue when it comes to the coin landing - e.g. the final result is random, but I'm hoping I can switch in the actual result at the end?)
Thanks in advance!
I recently wanted to implement something like this for a project. I finally came up with a solution and the result was good enough. Hope it helps someone else who is trying to achieve the same animation.
I uploaded the result as a gist on GitHub.
For a preview of the animation click here.
For the full android studio project visit our CoinToss repository.
I was looking for something like this myself, even with the scaling of the image so it appears the imageview is getting closer to the screen.
I combined your animation with this solution to do exactly what you wanted and its fairly lightweight, missing out the need for multiple views.
https://github.com/Lojko/Booty/blob/master/src/game/booty/BootyGameActivity.java
Changed Location of the Original Link: http://www.jasoncavett.com/2011/05/changing-images-during-an-android-animation/#comments
See the FlipCoin class and how its used, I have an animation already existing (created in the same way as detailed by the link)
This code shows the same procedure
http://www.inter-fuser.com/2009/08/android-animations-3d-flip.html

Categories

Resources