android 消息更新提示动画

转载地址:http://blog.csdn.net/xiaobijia/article/details/40738879

   在登陆应用时,信息有更新,为了引起用户注意,会有提示标签:

百度:


网易:

android 消息更新提示动画_第1张图片


     如果给标签加入动画效果,会更加醒目,如淘宝:




本例效果:

android 消息更新提示动画_第2张图片


使用属性动画实现,稍微修改就可以实现淘宝的效果

实现动画类:

[java]  view plain copy
  1. package com.example.swingaimation;  
  2.   
  3. import android.animation.Keyframe;  
  4. import android.animation.ObjectAnimator;  
  5. import android.animation.PropertyValuesHolder;  
  6. import android.annotation.SuppressLint;  
  7. import android.view.View;  
  8.   
  9.   
  10.   
  11.   
  12. public class AnimationUtils {  
  13.   
  14.     public static ObjectAnimator tada(View view) {  
  15.         return tada(view, 1f);  
  16.     }  
  17.   
  18.     @SuppressLint("NewApi")  
  19.     public static ObjectAnimator tada(View view, float shakeFactor) {  
  20.   
  21.         PropertyValuesHolder pvhScaleX = PropertyValuesHolder.ofKeyframe(View.SCALE_X,  
  22.                 Keyframe.ofFloat(0f, 1f),  
  23.                 Keyframe.ofFloat(.1f, .9f),  
  24.                 Keyframe.ofFloat(.2f, .9f),  
  25.                 Keyframe.ofFloat(.3f, 1.1f),  
  26.                 Keyframe.ofFloat(.4f, 1.1f),  
  27.                 Keyframe.ofFloat(.5f, 1.1f),  
  28.                 Keyframe.ofFloat(.6f, 1.1f),  
  29.                 Keyframe.ofFloat(.7f, 1.1f),  
  30.                 Keyframe.ofFloat(.8f, 1.1f),  
  31.                 Keyframe.ofFloat(.9f, 1.1f),  
  32.                 Keyframe.ofFloat(1f, 1f)  
  33.         );  
  34.   
  35.         PropertyValuesHolder pvhScaleY = PropertyValuesHolder.ofKeyframe(View.SCALE_Y,  
  36.                 Keyframe.ofFloat(0f, 1f),  
  37.                 Keyframe.ofFloat(.1f, .9f),  
  38.                 Keyframe.ofFloat(.2f, .9f),  
  39.                 Keyframe.ofFloat(.3f, 1.1f),  
  40.                 Keyframe.ofFloat(.4f, 1.1f),  
  41.                 Keyframe.ofFloat(.5f, 1.1f),  
  42.                 Keyframe.ofFloat(.6f, 1.1f),  
  43.                 Keyframe.ofFloat(.7f, 1.1f),  
  44.                 Keyframe.ofFloat(.8f, 1.1f),  
  45.                 Keyframe.ofFloat(.9f, 1.1f),  
  46.                 Keyframe.ofFloat(1f, 1f)  
  47.         );  
  48.   
  49.         PropertyValuesHolder pvhRotate = PropertyValuesHolder.ofKeyframe(View.ROTATION,  
  50.                 Keyframe.ofFloat(0f, 0f),  
  51.                 Keyframe.ofFloat(.1f, -3f * shakeFactor),  
  52.                 Keyframe.ofFloat(.2f, -3f * shakeFactor),  
  53.                 Keyframe.ofFloat(.3f, 3f * shakeFactor),  
  54.                 Keyframe.ofFloat(.4f, -3f * shakeFactor),  
  55.                 Keyframe.ofFloat(.5f, 3f * shakeFactor),  
  56.                 Keyframe.ofFloat(.6f, -3f * shakeFactor),  
  57.                 Keyframe.ofFloat(.7f, 3f * shakeFactor),  
  58.                 Keyframe.ofFloat(.8f, -3f * shakeFactor),  
  59.                 Keyframe.ofFloat(.9f, 3f * shakeFactor),  
  60.                 Keyframe.ofFloat(1f, 0)  
  61.         );  
  62.   
  63.         return ObjectAnimator.ofPropertyValuesHolder(view, pvhScaleX, pvhScaleY, pvhRotate).  
  64.                 setDuration(1000);  
  65.     }  
  66.   
  67.     @SuppressLint("NewApi")  
  68.     public static ObjectAnimator nope(View view) {  
  69.         int delta = view.getResources().getDimensionPixelOffset(R.dimen.activity_horizontal_margin);  
  70.   
  71.         PropertyValuesHolder pvhTranslateX = PropertyValuesHolder.ofKeyframe(View.TRANSLATION_X,  
  72.                 Keyframe.ofFloat(0f, 0),  
  73.                 Keyframe.ofFloat(.10f, -delta),  
  74.                 Keyframe.ofFloat(.26f, delta),  
  75.                 Keyframe.ofFloat(.42f, -delta),  
  76.                 Keyframe.ofFloat(.58f, delta),  
  77.                 Keyframe.ofFloat(.74f, -delta),  
  78.                 Keyframe.ofFloat(.90f, delta),  
  79.                 Keyframe.ofFloat(1f, 0f)  
  80.         );  
  81.   
  82.         return ObjectAnimator.ofPropertyValuesHolder(view, pvhTranslateX).  
  83.                 setDuration(500);  
  84.     }  
  85.   
  86. }  
主类即调用类:

[java]  view plain copy
  1. package com.example.swingaimation;  
  2.   
  3. import android.os.Bundle;  
  4. import android.annotation.SuppressLint;  
  5. import android.app.Activity;  
  6. import android.view.View;  
  7. import android.widget.ImageView;  
  8.   
  9. public class MainActivity extends Activity {  
  10.     //声明view  
  11.     private ImageView imageview;  
  12.   
  13.     @Override  
  14.     protected void onCreate(Bundle savedInstanceState) {  
  15.         super.onCreate(savedInstanceState);  
  16.         setContentView(R.layout.activity_main);  
  17.         //初始化view  
  18.         imageview = (ImageView) findViewById(R.id.imageview);  
  19.   
  20.     }  
  21.     // 整体摇动的动画点击事件  
  22.     @SuppressLint("NewApi")  
  23.     public void wholeShake(View view) {  
  24.         AnimationUtils.tada(imageview).start();  
  25.     }  
  26.     // 左右摇摆的动画  
  27.     @SuppressLint("NewApi")  
  28.     public void lefToRightShake(View view) {  
  29.         AnimationUtils.nope(imageview).start();  
  30.     }  
  31. }  

参考:

消息更新提示动画 - 下载频道 - CSDN.NET
http://download.csdn.net/detail/xiaobijia/8115009


你可能感兴趣的:(android 消息更新提示动画)