animation - Apply two alternate rotations to a View in Android -
I want to apply 2 alternative rotation animation in one view. Each rotation should start after clicking on the same view.
The result I am looking for:
- The user clicks the view and it rotates 0 degrees to 135 degrees
- Again on the user view Clicks and it rotates from 135 ° to 0 ° (to the initial stage)
The problem is that, when the user clicks on the second click, the button reset will start correctly with the initial animation The aspect before starting from
I'm targeting the Android API <11> I'm using the startAnimation () method to apply the animation to a button view defined as follows:
Android: Android: ID = "@ + ID / Button" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" /> Animations are as follows
rotate_cw.xml (0 ° to 135 ° rotation):
& lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Set xmlns: android = "http://schemas.android.com/apk/res/android" Android: fillAfter = "true" & gt; & Lt; Rotate Android: Period = "300" Android: fromDegrees = "0" Android: pivotX = "50%" Android: pivotY = "50%" Android: toDegrees = "135" /> & Lt; / Set & gt; rotate_ccw.xml (135 ° to 0 degree rotation):
& lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Set xmlns: android = "http://schemas.android.com/apk/res/android" & gt; Android: Android: Android: Android: Sedargriz = "135" Android: pivotX = "50%" Android: Pivat Y = "50%" Android: toDegrees = "0" /> & Lt; / Set & gt; Animation is then applied in a way where the flag is a boolean global variable:
button b = (button) findViewById (R.id. ); B.setOnClickListener (New View.OnClickListener) Click on {@Override Public Zero (view view) {if (flag) {animation A = animation high.load animation (this, R. anime.rttet_cw); B. Start animation ( A);} Other (Animation A = Animation: Load Animation (It, R. Anime RAttate® CCW); B. Start Animation (A);} Flag =! Flag;}}); Am I missing anything?
Thank you in advance for your help.
Comments
Post a Comment