Android tweened Animation notes

Source: Internet
Author: User

Layout file:

<relativelayout
xmlns:android= "Http://schemas.android.com/apk/res/android"
xmlns:tools= "Http://schemas.android.com/tools"
android:id= "@+id/activity_my_anim"
android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:paddingbottom= "@dimen/activity_vertical_margin"
android:paddingleft= "@dimen/activity_horizontal_margin"
android:paddingright= "@dimen/activity_horizontal_margin"
android:paddingtop= "@dimen/activity_vertical_margin"
tools:context= "Com.jogger.propertiesanim.MyAnim" >

<imageview
android:id= "@+id/iv_clock"
android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_centerinparent= "true"
android:src= "@drawable/t_clock"/>

<imageview
android:id= "@+id/iv_bettery"
android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_centerinparent= "true"
android:src= "@drawable/t_bettery"/>

<imageview
android:id= "@+id/iv_low_bettery"
android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_above= "@id/iv_clock"
android:layout_centerhorizontal= "true"
android:src= "@drawable/t_low_bettery"/>
<imageview
android:id= "@+id/iv_next"
android:layout_centerhorizontal= "true"
android:src= "@drawable/t_next"
android:layout_below= "@id/iv_clock"
android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"/>
<imageview
android:id= "@+id/iv_msg"
android:layout_centerhorizontal= "true"
android:src= "@drawable/t_first_msg"
android:layout_below= "@id/iv_next"
android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"/>

</RelativeLayout>
method One: Dynamic registration
Public class Myanim extends Appcompatactivity {
private ImageView Iv_low_bettery, Iv_next, iv_bettery;

/**
* tweened Animation case (zoom, pan, rotate)
*/
@Override
protected void OnCreate (Bundle savedinstancestate) {
super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_my_anim);
iv_low_bettery = (ImageView) Findviewbyid (r.id.iv_low_bettery);
Iv_next = (ImageView) Findviewbyid (r.id.iv_next);
iv_bettery = (ImageView) Findviewbyid (r.id.iv_bettery);
//Zoom animation
/**
* FromX: The x-axis multiplier at which to start scaling. such as 1.0f: the size of itself, such as 2.0f: twice times from their own start
ToX: The x-axis multiple of the end scale, reflected at the end of the width
FromY: The y-axis multiple of the start scale.
ToY: The y-axis multiple of the end scale.
pivotxtype:x Axis Zoom center point type; optional values are:
animation.relative_to_self relative to himself--common
animation.relative_to_parent Relative parent form
Animation.absolute Absolutely---not used.

Pivotxvalue: On the basis of pivotxtype, the position of the x-axis zoom Center. For example: 0.5f: The zoom Center is half the control's position. If it is 0.0f, it will be in the left position of the control itself
pivotytype:x Axis Zoom center point type;
Pivotyvalue: On the basis of pivotytype, the position of the y-axis Zoom center.
*/
scaleanimation scaleanimation = new Scaleanimation (1.0f, 1.5f, 1.0f, 1.5f, Animation
. Relative_to_self, 0.5f, Animation.relative_to_self, 0.5f);
//Panning animations
/**
* Fromxtype: The x-axis reference position at which the translation begins, generally using animation.relative_to_self
fromxvalue:x The starting multiple of the axis translation. On the basis of Fromxtype.
toxtype: End translation X-axis reference position
toxvalue:x The ending multiple of the axis translation.
Fromytype: The y-axis reference position at which to begin panning
Fromyvalue:y The starting multiple of the axis translation.
toytype: End translation's y-axis reference position
toyvalue:y The ending multiple of the axis translation.
*/
translateanimation translateanimation = new Translateanimation (Animation
. Relative_to_self, 0, animation.relative_to_self, 0, Animation.relative_to_self,
0, Animation.relative_to_self, 1f);
Scaleanimation.setrepeatcount (animation.infinite);//Set the number of repetitions, INFINITE to set infinite repetition
Translateanimation.setrepeatcount (animation.infinite);
Animationset set = new Animationset (false);
set.addanimation (scaleanimation);
set.addanimation (translateanimation);
Set.setduration (2000);//time to play a round of animation
Set.setrepeatmode (animation.reverse);//used to set the repetition of the animation, you can choose to REVERSE (reverse) and restart (start again)
//set.setrepeatcount (animation.infinite);//set cannot set infinite repetition directly
iv_low_bettery.startanimation (set);
translateanimation translateanimationnext = new Translateanimation (Animation
. Relative_to_self, 0, animation.relative_to_self, 0, Animation.relative_to_self,
0, Animation.relative_to_self, 1.1f);
translateanimationnext.setduration (+);
Translateanimationnext.setrepeatcount (animation.infinite);
Translateanimationnext.setrepeatmode (animation.reverse);
iv_next.startanimation (translateanimationnext);

/**
* fromdegrees: Start rotation angle, three point direction is 0 degrees, six point direction is 90 degrees.
todegrees: End Rotation angle
Pivotxtype: Referencing scaled animations
pivotxvalue: Referencing scaled animations
Pivotytype: Referencing scaled animations
pivotyvalue: Referencing scaled animations
*/
rotateanimation rotateanimation = new Rotateanimation (0, 360,animation.relative_to_self,0.5f,animation.relativ e_to_self,0.5f);
Rotateanimation.setrepeatmode (animation.reverse);
Rotateanimation.setrepeatcount (animation.infinite);
rotateanimation.setduration (+);
iv_bettery.startanimation (rotateanimation);
}
}


method Two: Static registration
Create the Anim folder under the Res directory and create the following 3 resource files:
Low_bettery_anim.xml:
<set xmlns:android= "Http://schemas.android.com/apk/res/android"
android:duration= "
android:repeatmode= "Reverse"
>
<translate
android:fromxdelta= "0"
android:fromydelta= "0"
android:repeatcount= "Infinite"
android:toxdelta= "0"
android:toydelta= "100%" ></translate>
<scale
android:fromxscale= "100%"
android:fromyscale= "100%"
android:pivotx= "50%"
android:pivoty= "
android:repeatcount= "Infinite"
android:toxscale= "150%"
android:toyscale= "150%" ></scale>
</set>

Next_anim.xml
 <set xmlns:android= "http://schemas.android.com/apk/res/ Android " 
android:duration=" + "
android:repeatmode=" reverse "


Android:fromxdelta= "0"
android:fromydelta=" 0 "
android:r Epeatcount= "Infinite"
Android:toxdelta= "0"
Android:toydelta= "100%" ></TRANSLATE>
</SET>
Bettery_anim.xml:
<set xmlns:android= "Http://schemas.android.com/apk/res/android"
android:duration= "
android:repeatmode= "Reverse" >
<!--pivotx 50% means self ---
<rotate
android:fromdegrees= "0.5"
android:pivotx= "50%"
android:pivoty= "50%"
android:repeatcount= "Infinite"
android:todegrees= "></rotate> "

</set>
Code interface:
Public class Myanim extends Appcompatactivity {
private ImageView Iv_low_bettery, Iv_next, iv_bettery;

/**
* tweened Animation case (zoom, pan, rotate)
*/
@Override
protected void OnCreate (Bundle savedinstancestate) {
super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_my_anim);
iv_low_bettery = (ImageView) Findviewbyid (r.id.iv_low_bettery);
Iv_next = (ImageView) Findviewbyid (r.id.iv_next);
iv_bettery = (ImageView) Findviewbyid (r.id.iv_bettery);
Animation Low_bettery_anim = Animationutils.loadanimation (this, r.anim.low_bettery_anim);
Animation Next_anim = Animationutils.loadanimation (this, r.anim.next_anim);
Animation Bettery_anim = Animationutils.loadanimation (this, r.anim.bettery_anim);
iv_next.startanimation (Next_anim);
iv_low_bettery.startanimation (Low_bettery_anim);
iv_bettery.startanimation (Bettery_anim);
}
}

:

Android tweened Animation notes

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.