Tween Animation

android:fromYScale="1.0"

android:toYScale="0.6"

android:pivotX="5 0%"

android:pivotY="5 0%"

android:fillAfter="false"

android:duration="7 00" />

<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

start0ffset="7 00"

android

duration="4 00"

android

fillBefore="false" />

<rotate

android

fromDegrees="0"

android

toDegrees="-4 5"

android

toYScale="0.0"

android

pivotX="50%"

android

pivotY="50%"

android

start0ffset="7 00"

android

duration="4 00" />

</set>

</set>

Screen coordinates (not used in this example) are (0,0) at the upper left hand corner, and increase as you go down and to the right.

Screen coordinates (not used in this example) are (0,0) at the upper left hand corner, and increase as you go down and to the right.

Some values, such as pivotX, can be specified relative to the object itself or relative to the parent. Be sure to use the proper format for what you want ("50" for 50% relative to the parent, or "50%" for 50% relative to itself).

You can determine how a transformation is applied over time by assigning an Interpolator. Android includes several Interpolator subclasses that specify various speed curves: for instance,AccelerateInterpolator tells a transformation to start slow and speed up. Each one has an attribute value that can be applied in the XML.

With this XML saved as hyperspace jump.xml in the res/anim/ directory of the project, the following Java code will reference it and apply it to an ImageView object from the layout.

ImageView spaceshipImage = (ImageView) findViewById(R.id.spaceshipImage);

Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(this, R.anim.hyperspace jump);

spaceshipImage.startAnimation(hyperspaceJumpAnimation); As an alternative to startAnimation() , you can define a starting time for the animation with Animation.setStartTime() , then assign the animation to the View withView.setAnimation() . For more information on the XML syntax, available tags and attributes, see the discussion on animation in the Available Resources.

Note: Regardless of how your animation may move or resize, the bounds of the View that holds your animation will not automatically adjust to accomodate it. Even so, the animation will still be drawn beyond the bounds of its View and will not be clipped. However, clipping will occur if the animation exceeds the bounds of the parent View.

0 0

Post a comment