How to make the Android view animation cycle bounce

Source: Internet
Author: User

Create folder Anim in Res, write down Cycles.xml,shake1.xml,shake2.xml

Cycles.xml:

1 <? XML version= "1.0" encoding= "Utf-8" ?> 2 <!--  -3<xmlns:android = "http//     Schemas.android.com/apk/res/android "4    android:cycles=" 1 "/> 

Shake1.xml:

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <!--Move Horizontally -3 <!--Android:duration representative Run time -4 <!--Android:fromxdelta represents the starting horizontal position (0,0) -5 <!--Android:toxdelta represents the x distance from the starting position of the horizontal axis (100,0) -6 <Translatexmlns:android= "Http://schemas.android.com/apk/res/android"7 android:duration= " the"8 Android:fromxdelta= "0.0"9 Android:toxdelta= "100.0"Ten Android:interpolator= "@anim/cycles"/>

Shake2.xml:

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <!--Move vertically -3 <!--Android:duration representative Run time -4 <!--Android:fromxdelta represents the starting ordinate position (0,0) -5 <!--Android:toxdelta represents the y distance from the start position of the horizontal axis (0,100) -6 <Translatexmlns:android= "Http://schemas.android.com/apk/res/android"7 android:duration= " the"8 Android:fromydelta= "0.0"9 Android:toydelta= "100.0"Ten Android:interpolator= "@anim/cycles"/>

Activity_main.xml:

1 <Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Xmlns:tools= "Http://schemas.android.com/tools"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent"5 Tools:context= "Com.zzw.testshake.MainActivity" >6 7     <ImageView8         Android:id= "@+id/image2"9 Android:layout_width= "100DP"Ten Android:layout_height= "100DP" One Android:layout_alignparentbottom= "true" A Android:layout_centerhorizontal= "true" - Android:layout_marginbottom= "78DP" - android:src= "@drawable/b" /> the  -     <ImageView -         Android:id= "@+id/image1" - Android:layout_width= "100DP" + Android:layout_height= "100DP" - Android:layout_alignleft= "@+id/image2" + Android:layout_alignparenttop= "true" A Android:layout_margintop= "87DP" at android:src= "@drawable /A" /> -  -     <Button -         Android:id= "@+id/button2" - style= "? Android:attr/buttonstylesmall" - Android:layout_width= "Wrap_content" in Android:layout_height= "Wrap_content" - Android:layout_above= "@+id/image2" to Android:layout_toleftof= "@+id/image2" + Android:text= "button" /> -  the  *     <Button $         Android:id= "@+id/button1"Panax Notoginseng style= "? Android:attr/buttonstylesmall" - Android:layout_width= "Wrap_content" the Android:layout_height= "Wrap_content" + Android:layout_below= "@+id/edittext1" A Android:layout_toleftof= "@+id/image1" the Android:text= "button" /> +  - </Relativelayout>
Activity_main.xml

Mainactivity:

1  PackageCom.zzw.testshake;2 3 Importandroid.app.Activity;4 ImportAndroid.os.Bundle;5 Importandroid.view.animation.AnimationUtils;6 ImportAndroid.widget.Button;7 ImportAndroid.widget.EditText;8 ImportAndroid.widget.ImageView;9 Ten  Public classMainactivityextendsActivity { One  A @Override -     protected voidonCreate (Bundle savedinstancestate) { -         Super. OnCreate (savedinstancestate); the Setcontentview (r.layout.activity_main); -          -ImageView Image1 =(ImageView) Findviewbyid (r.id.image1); -Image1.startanimation (Animationutils.loadanimation ( This, R.anim.shake1)); +  -ImageView Image2 =(ImageView) Findviewbyid (r.id.image2); +Image2.startanimation (Animationutils.loadanimation ( This, R.anim.shake2)); A  atButton BT1 =(Button) Findviewbyid (r.id.button1); -Bt1.startanimation (Animationutils.loadanimation ( This, R.anim.shake1)); -  -Button BT2 =(Button) Findviewbyid (r.id.button2); -Bt2.startanimation (Animationutils.loadanimation ( This, R.anim.shake2)); -  in     } -  to}

How to animate the view animation of Android

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.