Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Android Training (Animation)

819 views

Published on

Android Training (Animation)

Published in: Technology
  • Login to see the comments

  • Be the first to like this

Android Training (Animation)

  1. 1. Android Animation Android Training By Khaled Anaqwa
  2. 2. Animation  The Android framework provides two animation systems:  property animation (introduced in Android 3.0)  view animation. (using XML)  Both animation systems are viable options, but the property animation system, in general, is the preferred method to use, because it is more flexible and offers more features.
  3. 3. Property Animation  Introduced in Android 3.0 (API level 11)  lets you animate properties of any object, including ones that are not rendered to the screen.  The system is extensible and lets you animate properties of custom types as well.
  4. 4. Property Animation  Is a robust framework that allows you to animate almost anything.  You can define an animation to change any object property over time, regardless of whether it draws to the screen or not.  it’s changes a property's (a field in an object) value over a specified length of time.
  5. 5. Property Animation characteristics  Duration (The default length is 300 ms)  Time interpolation (function of the animation’s)  Repeat count and behavior  Animator sets (You can group animations into logical sets that play together or sequentially or after specified delays)  Frame refresh delay (The default is set to refresh every 10 ms)
  6. 6. Animator  The Animator class provides the basic structure for creating animations.  You normally do not use this class directly as it only provides minimal functionality that must be extended to fully support animating values.
  7. 7. Subclasses of Animator used  ValueAnimator This class provides a simple timing engine for running animations which calculate animated values and set them on target objects.  ObjectAnimator  This subclass of ValueAnimator provides support for animating properties on target objects.  The constructors of this class take parameters to define the target object that will be animated as well as the name of the property that will be animated.  it makes the process of animating values on target objects much easier  ObjectAnimator has a few more restrictions(Use ValueAnimator).  AnimatorSet  Provides a mechanism to group animations together so that they run in relation to one another.  You can set animations to play together, sequentially, or after a specified delay
  8. 8. Animating with ValueAnimator ValueAnimator animation= ValueAnimator.ofFloat(0f, 1f); animation.setDuration(2000); animation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator animation) { Float value = (Float) animation.getAnimatedValue(); Float frac = animation.getAnimatedFraction(); textView.setAlpha(value);} });
  9. 9. Animating with ObjectAnimator ObjectAnimator anim = ObjectAnimator.ofFloat(textview, "alpha", 0f, 1f); anim.setDuration(1000); anim.start();
  10. 10. AnimatorSet  AnimatorSet set1= new AnimatorSet();  Play()  Before()  With()  After()  Note : you can play set into another set AnimatorSet set2= new AnimatorSet(); Set2.paly(set1).before(anim);
  11. 11. Declaring Animations in XML <set android:ordering="sequentially"> <set> <objectAnimator android:propertyName="x" android:duration="500" android:valueTo="400" android:valueType="intType"/> <objectAnimator android:propertyName="y" android:duration="500" android:valueTo="300" android:valueType="intType"/> </set> <objectAnimator android:propertyName="alpha" android:duration="500" android:valueTo="1f"/> </set> ValueAnimator - <animator> ObjectAnimator - <objectAnimator> AnimatorSet - <set>
  12. 12. Load Animation AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(myContext, R.anim.property_animator); set.setTarget(myObject); set.start();

×