Android第四十四期 - 登录界面的动画
这次是需求有点无语,不过还是做出来了,效果如下,这回要讲讲,有点复杂,以后自己估计都忘了,记录一下--! 动画类AnimalUtul: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 public class AnimalUtul{ private AnimatorSetmAnimatorSet; RelativeLayoutrl_parent; private ImageViewiv_logo; private float mLogoY; private Contextcontext; private long starttime= 1500 ; public long getStarttime(){ return starttime; } public void setStarttime( long starttime){ this .starttime=starttime; } public AnimalUtul(Contextcontext,RelativeLayoutlayout,ImageViewlogo){ iv_logo=logo; rl_parent=layout; this .context=context; iv_logo.postDelayed( new Runnable(){ @Override public void run(){ if (mLogoY== 0 ){ mLogoY=ViewHelper.getY(iv_logo); } playLogoInAnim(); } },starttime); iv_logo.postDelayed( new Runnable(){ @Override public void run(){ playInAnim(); } },starttime); } public void playInAnim(){ rl_parent.setVisibility(View.VISIBLE); AnimatorSetmAnimatorSet; ObjectAnimatoranim3=ObjectAnimator.ofFloat(rl_parent, "y" , DisplayUtil.getDisplayheightPixels(context), DisplayUtil.dip2px(context, 160 )); mAnimatorSet= new AnimatorSet(); mAnimatorSet.play(anim3); mAnimatorSet.setDuration( 1000 ); mAnimatorSet.start(); } private void playLogoInAnim(){ ObjectAnimatoranim1=ObjectAnimator.ofFloat(iv_logo, "scaleX" , 1 .0f, 0 .5f); ObjectAnimatoranim2=ObjectAnimator.ofFloat(iv_logo, "scaleY" , 1 .0f, 0 .5f); ObjectAnimatoranim3=ObjectAnimator.ofFloat(iv_logo, "y" ,mLogoY, DisplayUtil.dip2px(context, 15 )); if (mAnimatorSet!= null &&mAnimatorSet.isRunning()){ mAnimatorSet.cancel(); mAnimatorSet= null ; } mAnimatorSet= new AnimatorSet(); mAnimatorSet.play(anim1).with(anim2); mAnimatorSet.play(anim2).with(anim3); mAnimatorSet.setDuration( 1000 ); mAnimatorSet.start(); } } 适配屏幕高度类DisplayUtil: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 public class DisplayUtil{ /**屏幕宽度*/ private static int DisplayWidthPixels= 0 ; /**屏幕高度*/ private static int DisplayheightPixels= 0 ; /** *获取屏幕参数 *@paramcontext */ private static void getDisplayMetrics(Contextcontext){ DisplayMetricsdm= new DisplayMetrics(); ((Activity)context).getWindowManager().getDefaultDisplay().getMetrics(dm); //宽度 DisplayWidthPixels=dm.widthPixels; //高度 DisplayheightPixels=dm.heightPixels; } /** *获取屏幕宽度 *@paramcontext *@return */ public static int getDisplayWidthPixels(Contextcontext){ if (context== null ){ return - 1 ; } if (DisplayWidthPixels== 0 ){ getDisplayMetrics(context); } return DisplayWidthPixels; } /** *获取屏幕高度 *@paramcontext *@return */ public static int getDisplayheightPixels(Contextcontext){ if (context== null ){ return - 1 ; } if (DisplayheightPixels== 0 ){ getDisplayMetrics(context); } return DisplayheightPixels; } /** *将px值转换为dip或dp值 * *@parampxValue *@return */ public static int px2dip(Contextcontext, float pxValue){ final float scale=context.getResources().getDisplayMetrics().density; return ( int )(pxValue/scale+ 0 .5f); } /** *将dip或dp值转换为px值 * *@paramdipValue *@return */ public static int dip2px(Contextcontext, float dipValue){ final float scale=context.getResources().getDisplayMetrics().density; return ( int )(dipValue*scale+ 0 .5f); } /** *将px值转换为sp值 * *@parampxValue *@return */ public static int px2sp(Contextcontext, float pxValue){ final float fontScale=context.getResources().getDisplayMetrics().scaledDensity; return ( int )(pxValue/fontScale+ 0 .5f); } /** *将sp值转换为px值 *@paramspValue *@return */ public static int sp2px(Contextcontext, float spValue){ final float fontScale=context.getResources().getDisplayMetrics().scaledDensity; return ( int )(spValue*fontScale+ 0 .5f); } } 调用方法:newAnimalUtul(this,出现的layout,logo图片); 唉~好累~天天写这些--! 本文转自 吴雨声 51CTO博客,原文链接:http://blog.51cto.com/liangxiao/1673192,如需转载请自行联系原作者