Android Interstitial animation effects

Source: Internet
Author: User

The company developed the SDK, need similar to have the animation effect of rice interstitial, researched, wrote a demo, stare very specific.


<span style= "FONT-SIZE:24PX;" >package Com.example.animationactivity;import Android.animation.animator;import Android.animation.AnimatorSet; Import Android.animation.ObjectAnimatoimport Android.annotation.suppresslint;import android.content.Context; Import Android.os.bundle;import Android.support.v7.app.actionbaractivity;import Android.view.view;import Android.view.view.onclicklistener;import Android.view.windowmanager;import android.view.animation.AlphaAnimation ; Import Android.view.animation.animation;import Android.view.animation.animationset;import Android.view.animation.animationutils;import Android.view.animation.scaleanimation;import Android.view.animation.translateanimation;import Android.widget.button;import Android.widget.ImageView;import Android.widget.RelativeLayout, @SuppressLint ("Newapi") public class Mainactivity extends Actionbaractivity {private Button button;imageview image;private int a = 1; @Overrideprotected void OnCreate (Bundle savedinstancestate) { Super.oncreate (SAvedinstancestate); Setcontentview (r.layout.activity_main); button = (button) Findviewbyid (R.id.button); image = new ImageView (Getapplicationcontext ()); Image.setimagedrawable (Getresources (). getdrawable (R.DRAWABLE.BG1)); Relativelayout.layoutparams params = new Relativelayout.layoutparams ((int) (GetWidth (Getapplicationcontext ()) * 0.8), (int) (GetHeight (Getapplicationcontext ()) * 0.8)); Params.addrule (relativelayout.center_in_parent); Relativelayout relativelayout = (relativelayout) Findviewbyid (r.id.parent); Image.setlayoutparams (params);         Relativelayout.addview (image); /**//animation 1final Animation Animation = new Translateanimation ( -600f, 0f, 0f, 0f); final Animation scaleanimation = new Scalea Nimation (0.2f, 1f, 0.2f, 1f), final animationset animationset = new Animationset (true); Animationset.addanimation ( scaleanimation); animationset.addanimation (animation); animationset.setduration (1000); Animation translationanimation = new Translateanimation (0f, 1800f, 0f,0f); Animation ScaleAnimation2 = new SCaleanimation (1f, 0.4f, 1f, 0.4f); final Animationset AnimationSet2 = new Animationset (true); animationset2.addanimation (translationanimation); animationset2.addanimation (ScaleAnimation2); animationset2.setduration (1000);       Animationset2.setfillafter (TRUE); **/button.setonclicklistener (New Onclicklistener () {@SuppressLint ("Newapi") @Overridepublic void OnClick (View v) {// TODO auto-generated Method stub//writes itself/** * if (a = = 1) {a = 2; image.startanimation (animationset);} * Else {a = 1; IMA Ge.startanimation (AnimationSet2); **///the animated if (a = = 1) {enteranimation (image, Getapplicationcontext ()) from the meter, and a = 2;} else {backanimation (image, Getappli Cationcontext ()); a = 1;}});} Gets the width of the screen public static int getwidth (context context) {WindowManager WindowManager = (WindowManager) Context.getsystemservice (context.window_service); int width = Windowmanager.getdefaultdisplay (). GetWidth (); return width;} Gets the height of the screen public int getheight (context context) {WindowManager WindowManager = (WindowManager) contExt.getsystemservice (context.window_service); int height = Windowmanager.getdefaultdisplay (). GetHeight (); return Height;} Go out animation public static void Backanimation (ImageView Paramview, context context) {int f = (getwidth (context)-PARAMVIEW.GETW Idth ())/2;paramview.setpivotx (Paramview.getwidth ()/2);p Aramview.setpivoty (Paramview.getheight ()/2); O Bjectanimator LocalObjectAnimator1 = objectanimator.offloat (Paramview, "ScaleX", new float[] {1.0F, 0.8F}). setduration (1L); Objectanimator LocalObjectAnimator2 = Objectanimator.offloat (Paramview, "ScaleY", new float[] {1.0F, 0.8F}). Setduration (1L); Objectanimator LocalObjectAnimator3 = Objectanimator.offloat (Paramview, "Alpha", new float[] {1.0F, 0.7F}). Setduration (1L); Objectanimator LocalObjectAnimator4 = Objectanimator.offloat (Paramview, "X", new float[] {f, GetWidth (Context)}). Setduration (800L); Objectanimator LocalObjectAnimator5 = Objectanimator.offloat (Paramview, " ScaleX ", new float[] {0.8F, 1.0F}). Setduration (400L); LocalObjectAnimator5.Setstartdelay (400L); Objectanimator localObjectAnimator6 = Objectanimator.offloat (Paramview, "ScaleY", new float[] { 0.8F, 1.0F}). Setduration (400L); Localobjectanimator6.setstartdelay (400L); Objectanimator localObjectAnimator7 = Objectanimator.offloat (Paramview, "Alpha", new float[] {0.7F, 1.0F}). Setduration (400L); Localobjectanimator7.setstartdelay (400L); Animatorset localanimatorset = new Animatorset () Localanimatorset.playtogether (new animator[] {localObjectAnimator1, LocalObjectAnimator2, Localobjectanimator3,localobjectanimator4, Localobjectanimator5,localobjectanimator6, LOCALOBJECTANIMATOR7}); Localanimatorset.start ();} Enter the animation public static void Enteranimation (ImageView Paramview, Context context) {//the width of the screen minus the width of the animation. is the distance to move the picture int f = (getwidth (context)-paramview.getwidth ())/2;paramview.setpivotx (Paramview.getwidth ()/2); Paramview.setpivoty (Paramview.getheight ()/2); Objectanimator LocalObjectAnimator1 = Objectanimator.offloat ( Paramview, "ScaleX", new float[] {1.0F, 0.8F}). Setduration (1L); Objectanimator LocalObjectAnimator2 = Objectanimator.offloat (Paramview, "ScaleY", new float[] {1.0F, 0.8F}). Setduration (1L); Objectanimator LocalObjectAnimator3 = Objectanimator.offloat (Paramview, "Alpha", new float[] {1.0F, 0.7F}). Setduration (1L); Objectanimator LocalObjectAnimator4 = Objectanimator.offloat (Paramview, "X", new float[] {- Paramview.getwidth (), F}). Setduration (800L); Objectanimator LocalObjectAnimator5 = Objectanimator.offloat (paramview , "ScaleX", new float[] {0.8F, 1.0F}). Setduration (400L); Localobjectanimator5.setstartdelay (400L); objectanimator LocalObjectAnimator6 = Objectanimator.offloat (Paramview, "ScaleY", new float[] {0.8F, 1.0F}). Setduration (400L); Localobjectanimator6.setstartdelay (400L); Objectanimator localObjectAnimator7 = Objectanimator.offloat (Paramview, " Alpha ", new float[] {0.7F, 1.0F}). Setduration (400L); Localobjectanimator7.setstartdelay (400L); Animatorset localanimatorset = new Animatorset () Localanimatorset.playtogether (new animator[] {localObJectanimator1,localobjectanimator2, Localobjectanimator3,localobjectanimator4, LocalObjectAnimator5, LocalObjectAnimator6, localObjectAnimator7}); Localanimatorset.start ();}} </span><span style= "FONT-SIZE:18PX;" ></span>

Android Interstitial animation effects

Related Article

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.