Professional Documents
Culture Documents
Android - Lecture 10 - Animation
Android - Lecture 10 - Animation
Animation
Basic Layout
TextView
Create an anim folder under your res directory to hold your animation files Then create a new fade_in.xml directory
Fade In Parameters
Parameter fromAlpha toAlpha duration Description The initial opacity 0 is invisible. 1 is fully visible The ending opacity 0 is invisible. 1 is fully visible How long in milliseconds the animation takes
1. Create the startAnimation funciton in your Activity Access the TextView Create the fade In Animation Then start the fade In Animation applying it to the TextView
Animation can be expensive. Potentially it could take a while, or it could take resources Hence, we need to stop the animation when the user requests to go to another screen, or it is interrupted by another means
Pause Method
the TextView by its id call the clear animation for the TextView
Resume Method
Now we will fade the second TextView in after an amount of seconds. Create a fade_in2.xml and add the offset property
Add an Image
Lets add an ImageView between the two titles. Your page should now look as follows:
Rotating Animation
Rotating
Description The degree the item starts out at 0, 360 original position, 180 flipped
Parameter fromDegrees
toDegrees
pivotX
The degree the item ends out at 0, 360 original position, 180 flipped
How much it pivots around the x axis in a percent of its width
pivotY
duration
You will create a LayoutAnimationController which you can use to animate all views within a particular layout. e.g. Animate all items in your LinearLayout First assign an Id to your LinearLayout
Access the custom_anim xml and create an Animation Object for it Create a LayoutAnimationController based on the Animation Object you created
Attach an AnimationListener to listen to the end of the Animation When the end of the animation is encountered we will proceed to the next Activity
Before proceeding make sure to create a new Activity and register it in the Manifest file Also, take out the code to Animate all views and lets work with the individual views.
Create an AnimationListener
When the Animation Ends end this Activity and start the next
We will attach the event listener to the animation that will finish last as follows: