android animations pdf by apk855

VIEWS: 51 PAGES: 11

More Info
									               Animations


                       Copyright © 2012, apkdownloads.in. All rights
ANIMATIONS-1
                                                          reserved
     • The Android framework provides two animation
       systems
         property animation (introduced in Android 3.0).
         view animation.
     • 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.
     • In addition to these two systems, you can utilize
       Drawable animation, which allows you to load
       drawable resources and display them one frame after
       another.

                                          Copyright © 2012, apkdownloads.in. All rights
ANIMATIONS-2
                                                                             reserved
     • The view animation system provides the capability to
       only animate View objects.
     • so if you wanted to animate non-View objects, you
       have to implement your own code to do so.
     • The view animation system is also constrained in the
       fact that it only exposes a few aspects of a View
       object to animate, such as the scaling and rotation of
       a View but not the background color, for instance.
     • Another disadvantage of the view animation system
       is that it only modified where the View was drawn,
       and not the actual View itself.
     • For instance, if you animated a button to move
       across the screen, the button draws correctly, but
       the actual location where you can click the button
       does not change, so you have to implement your
       own logic to handle this.
                                          Copyright © 2012, apkdownloads.in. All rights
ANIMATIONS-3
                                                                             reserved
     • With the property animation system, these
       constraints are completely removed.
     • you can animate any property of any object (Views
       and non-Views) and the object itself is actually
       modified.
     • The property animation system is also more robust
       in the way it carries out animation.
     • At a high level, you assign animators to the
       properties that you want to animate, such as color,
       position, or size and can define aspects of the
       animation such as interpolation and synchronization
       of multiple animators.
     • It also might make sense to use both animation
       systems for different situations if the use case
       arises.
                                        Copyright © 2012, apkdownloads.in. All rights
ANIMATIONS-4
                                                                           reserved
                         View Animation

     • We use View Animation system to perform tweened
       animation on Views.
     • Tween animation calculates the animation with
       information such as the start point, end point, size,
       rotation and other common aspects of an animation.
     • A tween animation can a series of simple
       transformations on the contents of a View object.
     • If you a TextView object, you can move , rotate, grow,
       or shrink the text.
     • If it having a background image , the image will be
       transformed along with the text.
     • The android.view.animation package provides the
       classes for tweened animations.
                                          Copyright © 2012, apkdownloads.in. All rights
ANIMATIONS-5
                                                                             reserved
     • To perform a tween animation we need to defines the
       instructions either by .XML file or Android Code.
     • As we work with the layout, .xml file gives you the
       flexibility and readability.
     • The animation instructions (transformations )are
       either sequential or simultaneous.
     • Each transformation takes           a set of specific
       parameters .
     • To     make      several     transformations  happen
       simultaneously, give them the same start time; to
       make them sequential, calculate the start time plus
       the duration of the preceding transformation.

                                         Copyright © 2012, apkdownloads.in. All rights
ANIMATIONS-6
                                                                            reserved
     • The animation xml file belongs in the res/anim/
       directory of your android project.
     • The file must have a single root element <set>.
     • The child element may be
       <alpha>,<scale>,<translate>,<rotate>.
     • The <set> may contain one more <set> element.
     • By default, all animation instructions are applied
       simultaneously.
     • To make them occur sequentially, you must specify
       the startOffSet attribute.
     • The following .xml file is used to stretch, then
       simultaneously spin and rotate a View Object.

                                         Copyright © 2012, apkdownloads.in. All rights
ANIMATIONS-7
                                                                            reserved
       <set android:shareInterpolator="false">
            <scale
              android:interpolator="@android:anim/accelerate_decelerate_i
         nterpolator"
              android:fromXScale="1.0”         android:toXScale="1.4"
              android:fromYScale="1.0”         android:toYScale="0.6"
              android:pivotX="50%“            android:pivotY="50%"
              android:fillAfter="false“       android:duration="700" />
            <set
         android:interpolator="@android:anim/decelerate_interpolator">
              <scale
                android:fromXScale="1.4“           android:toXScale="0.0"
                android:fromYScale="0.6“           android:toYScale="0.0"
                android:pivotX="50%”              android:pivotY="50%"
                android:startOffset="700“         android:duration="400"
                android:fillBefore="false" />
              <rotate
                android:fromDegrees="0“            android:toDegrees="-45"
                android:toYScale="0.0“            android:pivotX="50%"
                android:pivotY="50%“             android:startOffset="700"
                android:duration="400" />
            </set>
         </set>
                                                Copyright © 2012, apkdownloads.in. All rights
ANIMATIONS-8
                                                                                   reserved
                              Activity file

  • To apply the above animations, we use the following
    java code .

  •   ImageView image = (ImageView) findViewById(R.id.imageView1);
      Animation hyperspaceJumpAnimation =
      AnimationUtils.loadAnimation(this,
      R.anim.animation_hyperjump);
      spaceshipImage.startAnimation(hyperspaceJumpAnimation);




  • As an alternative to startAnimation(), we can setup the
    starting time .

                                              Copyright © 2012, apkdownloads.in. All rights
ANIMATIONS-9
                                                                                 reserved
                                PropertyAnimation

     • By using PropertyAnimation , You can define an
       animation to change any object property over time.
     • To animate anything, we specify the following
       things:
               The object property that you want to animate.
               Object’s position on the screen.
               How long you want to animate the object.
               What values you want to animate in between.
     • The property animation system lets you define the
       following characteristics of the animation:
           Duration : Specifies the duration of an animation. The
                       default duration length is 300ms.
           Time Interpolation : You can specify how the values for the
                                 property are calculated as a function of
                                 the animation’s current elapsed time.
                                                      Copyright © 2012, apkdownloads.in. All rights
ANIMATIONS-10
                                                                                         reserved
     • Repeat count and behavior: specifies whether the
                      animation is to be repeated or not.
                      And if it is repeated how many no of
                      times it should repeated.

     • Animator Sets: You can group animation into
                      logical sets that play together or
                      sequentially.

     • FrameRefreshDelay : specifies how often to refresh
                     frames of your animation.


                                          Copyright © 2012, apkdownloads.in. All rights
ANIMATIONS-11
                                                                             reserved

								
To top