Xamarin Android Development: Animation Interpolator

Source: Internet
Author: User

Xamarin Android in the development of several kinds of animation, here to summarize one of the interpolator, to achieve some simple translation, zoom, rotation, transparency changes and other animations, basically enough, do page jump can be used.


1,classification of Interpolator

Android:interpolator: accelerators, very useful properties, can be simply understood as the speed of the animation, can be more and more quickly, or it can be more and more slowly, or is fast after the busy, or even the speed, and so on, for the values as follows:

  • @android: Anim/accelerate_interpolator : getting faster
  • @android: Anim/decelerate_interpolator : More and more slowly
  • @android: Anim/accelerate_decelerate_interpolator : Fast and Slow first
  • @android: anim/anticipate_interpolator: One small step, and then it's speeding forward .
  • @android: Anim/overshoot_interpolator : Quickly reaches the end of a small step and then goes back to the end
  • @android: Anim/anticipate_overshoot_interpolator : Reach the end of a small step and return to the end
  • @android: Anim/bounce_interpolator : To reach the end to produce a pinball effect, bounce back to the end
  • @android: Anim/linear_interpolator : Uniform speed.


2, several animations

Alpha Animation:

<set xmlns:android= "http://schemas.android.com/apk/res/android"      android:interpolator= "@android: anim/ Accelerate_interpolator ">      <alpha          android:fromalpha=" 1.0 "          android:toalpha=" 0.0 "          android: startoffset= "android:duration="       />    </set>
Scale Animation:

<set xmlns:android= "http://schemas.android.com/apk/res/android"      android:interpolator= "@android: anim/ Accelerate_interpolator ">      <scale          android:fromxscale=" 1.0 "          android:toxscale=" 0.0 "          Android : fromyscale= "1.0"          android:toyscale= "0.0"          android:pivotx= "50%"          android:pivoty= "50%"          android: duration= "      /> </set>"    
Rotate animations:

<set xmlns:android= "http://schemas.android.com/apk/res/android"      android:interpolator= "@android: anim/ Accelerate_interpolator ">      <translate          android:fromxdelta=" 50% "          android:toxdelta=" 100% "          android:fromydelta= "50%"          android:toydelta= "100%"          android:duration= "the      "/>    </ Set>
Translate animations:
<set xmlns:android= "http://schemas.android.com/apk/res/android"      android:interpolator= "@android: anim/ Accelerate_interpolator ">      <translate          android:fromxdelta=" 50% "          android:toxdelta=" 100%          " Android:fromydelta= "50%"          android:toydelta= "100%"          android:duration= "+"      />    </set>
Attribute Explanation:

Duration: animation run time, defined in multiple times ( Ms ) to complete the animation within

Startoffset: Run animations after a certain amount of delay

Fromxdelta: X the starting position of the axis direction, can be % , or it can be a specific pixel See figure in detail

Toxdelta: End position of X - axis, either %or specific pixel

Fromydelta: Y the starting position of the axis direction, can be % , or it can be a specific pixel

Toydelta: Y the end position of the axis direction, which can be % , or it can be a specific pixel

Fromalpha: Start Transparency

Toalpha: Ending transparency

Pivotx: Anchor point x coordinate

Pivoty: The y-coordinate of the anchor point


3,translate animation example





defines an upward exiting animation (from the position 2 Move Position 3 ) and enter from below (from position 1 Move Position 2 The animation definition file is as follows:

Note that the XML is not the same as above, a separate translate tag, not set in the set

Out_to_up.xml ( exit from top of screen )

<?xml version= "1.0" encoding= "Utf-8"? ><translate xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:interpolator=" @android: Anim/accelerate_interpolator "    android:fromydelta=" 0%p "    Android:toydelta= " -100%p"    android:duration= "></translate>"
In_from_down.xml (enter from the bottom of the screen)
<?xml version= "1.0" encoding= "Utf-8"? ><translate xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:interpolator=" @android: Anim/accelerate_interpolator "    android:fromydelta=" 100%p "    Android:toydelta= "0%p"    android:duration= "></translate>"
The animation above can be used for activity switching.


4, composite animation

You can define multiple animation in the XML file so that multiple animation can run together, for example:

<?xml version= "1.0" encoding= "Utf-8"?> <set  xmlns:android= "http://schemas.android.com/apk/res/ Android "      android:interpolator=" @android: Anim/accelerate_interpolator "      android:shareinterpolator=" true "      >      <alpha          android:fromalpha= "1.0"          android:toalpha= "0.0"          android:startoffset= "500"          android:duration= "              />      <rotate          android:fromdegrees=" 0 "          android:todegrees=" "          android:pivotx=" 50% "          android:pivoty=" 50% "          android:duration=      "/> "    
Each animation effect can be overlaid with a set tag for better results.


5, using animations

Define an animation, associate an XML file, and then call the Startanimation function of an interface element

var in_animation = Animationutils.loadanimation (this, Resource.Animation.zoom_in), object. Startanimation (in_animation);

Xamarin Android Development: Animation Interpolator

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.