[2017-8-2] Android Learning Day8

Source: Internet
Author: User

Custom animation effects

Create a new Customanim class

1  Packagecom.liwenchi.myapplication;2 3 Importandroid.view.animation.Animation;4 Importandroid.view.animation.Transformation;5 6 Import Staticjava.lang.math.*;7 8 /**9 * Created by VULCAN on 2017/8/2.Ten  */ One  A  Public classCustomanimextendsAnimation { -  - @Override the     protected voidApplytransformation (floatInterpolatedtime, Transformation t) { -         //Interpolatedtime represents the time of the tween animation, starting with the 0~1,0 delegate, 1 representing the end -         //T stands for changing objects -         floatp =Interpolatedtime; +         Super. Applytransformation (Interpolatedtime, t); -         //System.out.println (interpolatedtime); +         //T.setalpha (interpolatedtime); set transparency A         //T.getmatrix (). Settranslate (0, -300*p); Set Location atT.getmatrix (). Settranslate ((float) (Sin (p*2*6.28*p) *50), 0); -     } -}

Where, overriding the Applytransformation () method

Create a Customanim animation in Mainactivity.java

1  Packagecom.liwenchi.myapplication;2 3 Importandroid.support.v7.app.AppCompatActivity;4 ImportAndroid.os.Bundle;5 ImportAndroid.view.View;6 Importandroid.view.animation.AlphaAnimation;7 Importandroid.view.animation.Animation;8 ImportAndroid.view.animation.AnimationSet;9 Importandroid.view.animation.AnimationUtils;Ten Importandroid.view.animation.RotateAnimation; One Importandroid.view.animation.ScaleAnimation; A Importandroid.view.animation.TranslateAnimation; - ImportAndroid.widget.Button; - ImportAndroid.widget.CheckBox; the ImportAndroid.widget.CompoundButton; - ImportAndroid.widget.TextView; -  -  Public classMainactivityextendsappcompatactivity { +  -     PrivateCustomanim CA; +  A @Override at     protected voidonCreate (Bundle savedinstancestate) { -         Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); - slove (); -     } -  in     Private voidSlove () { -CA =NewCustomanim (); toCa.setduration (1000); +Findviewbyid (R.ID.BTN). Setonclicklistener (NewView.onclicklistener () { -  the @Override *              Public voidOnClick (View v) { $ V.startanimation (CA);Panax Notoginseng             } -         }); the     } + } A //v.startanimation (Animationutils.loadanimation (Mainactivity.this, R.anim.ta));

This allows you to customize a "shake" animation effect

[2017-8-2] Android Learning Day8

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.