Android仿Iphone图标抖动效果

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

http://blog.csdn.net/long33long/article/details/7693671

最近闲来无聊,研究了一下IPhone桌面图标的抖动,网上有一个类似的事例,但是我看来效果实在不佳,自己也来写一个玩玩,当然代码很乱,杂乱无章,不满意的别骂我啊,当然也欢迎一起交流啊,嚯嚯

首先是JAVA代码ShakeTestActivity.java

[java]  view plain copy
  1. package com.android.shake;  
  2.   
  3. import android.app.Activity;  
  4. import android.os.Bundle;  
  5. import android.util.DisplayMetrics;  
  6. import android.view.animation.Animation;  
  7. import android.view.animation.Animation.AnimationListener;  
  8. import android.view.animation.RotateAnimation;  
  9. import android.widget.TextView;  
  10. import android.view.View;  
  11. import android.view.Window;  
  12.   
  13. public class ShakeTestActivity extends Activity implements View.OnClickListener {  
  14.     private TextView mtv0;  
  15.     private TextView mtv1;  
  16.     private TextView mtv2;  
  17.     private TextView mtv3;  
  18.     private TextView mtv4;  
  19.     private TextView mtv5;  
  20.     private TextView mtv6;  
  21.     private TextView mtv7;  
  22.     private TextView mtv8;  
  23.     private TextView mtv9;  
  24.     private TextView mtv10;  
  25.     private TextView mtv11;  
  26.     private TextView mtv12;  
  27.     private TextView mtv13;  
  28.     private TextView mtv14;  
  29.     private TextView mtv15;  
  30.     private TextView mtv16;  
  31.     private TextView mtv17;  
  32.     private TextView mtv18;  
  33.     private TextView mtv19;  
  34.   
  35.     private boolean mNeedShake = false;  
  36.     private boolean mStartShake = false;  
  37.   
  38.     private static final int ICON_WIDTH = 80;  
  39.     private static final int ICON_HEIGHT = 94;  
  40.     private static final float DEGREE_0 = 1.8f;  
  41.     private static final float DEGREE_1 = -2.0f;  
  42.     private static final float DEGREE_2 = 2.0f;  
  43.     private static final float DEGREE_3 = -1.5f;  
  44.     private static final float DEGREE_4 = 1.5f;  
  45.     private static final int ANIMATION_DURATION = 80;  
  46.   
  47.     private int mCount = 0;  
  48.   
  49.     float mDensity;  
  50.   
  51.     /** Called when the activity is first created. */  
  52.     @Override  
  53.     public void onCreate(Bundle savedInstanceState) {  
  54.         super.onCreate(savedInstanceState);  
  55.         requestWindowFeature(Window.FEATURE_NO_TITLE);  
  56.         setContentView(R.layout.main);  
  57.         DisplayMetrics dm = new DisplayMetrics();  
  58.         getWindowManager().getDefaultDisplay().getMetrics(dm);  
  59.         if (dm != null) {  
  60.             mDensity = dm.density;  
  61.         }  
  62.         mtv0 = (TextView) findViewById(R.id.tv0);  
  63.         mtv0.setOnClickListener(this);  
  64.         mtv1 = (TextView) findViewById(R.id.tv1);  
  65.         mtv1.setOnClickListener(this);  
  66.         mtv2 = (TextView) findViewById(R.id.tv2);  
  67.         mtv2.setOnClickListener(this);  
  68.         mtv3 = (TextView) findViewById(R.id.tv3);  
  69.         mtv3.setOnClickListener(this);  
  70.         mtv4 = (TextView) findViewById(R.id.tv4);  
  71.         mtv4.setOnClickListener(this);  
  72.         mtv5 = (TextView) findViewById(R.id.tv5);  
  73.         mtv5.setOnClickListener(this);  
  74.         mtv6 = (TextView) findViewById(R.id.tv6);  
  75.         mtv6.setOnClickListener(this);  
  76.         mtv7 = (TextView) findViewById(R.id.tv7);  
  77.         mtv7.setOnClickListener(this);  
  78.         mtv8 = (TextView) findViewById(R.id.tv8);  
  79.         mtv8.setOnClickListener(this);  
  80.         mtv9 = (TextView) findViewById(R.id.tv9);  
  81.         mtv9.setOnClickListener(this);  
  82.         mtv10 = (TextView) findViewById(R.id.tv10);  
  83.         mtv10.setOnClickListener(this);  
  84.         mtv11 = (TextView) findViewById(R.id.tv11);  
  85.         mtv11.setOnClickListener(this);  
  86.         mtv12 = (TextView) findViewById(R.id.tv12);  
  87.         mtv12.setOnClickListener(this);  
  88.         mtv13 = (TextView) findViewById(R.id.tv13);  
  89.         mtv13.setOnClickListener(this);  
  90.         mtv14 = (TextView) findViewById(R.id.tv14);  
  91.         mtv14.setOnClickListener(this);  
  92.         mtv15 = (TextView) findViewById(R.id.tv15);  
  93.         mtv15.setOnClickListener(this);  
  94.         mtv16 = (TextView) findViewById(R.id.tv16);  
  95.         mtv16.setOnClickListener(this);  
  96.         mtv17 = (TextView) findViewById(R.id.tv17);  
  97.         mtv17.setOnClickListener(this);  
  98.         mtv18 = (TextView) findViewById(R.id.tv18);  
  99.         mtv18.setOnClickListener(this);  
  100.         mtv19 = (TextView) findViewById(R.id.tv19);  
  101.         mtv19.setOnClickListener(this);  
  102.   
  103.     }  
  104.   
  105.     @Override  
  106.     public void onClick(View v) {  
  107.   
  108.         if (!mStartShake) {  
  109.             mStartShake = true;  
  110.             mNeedShake = true;  
  111.             shakeAnimation(mtv0);  
  112.             shakeAnimation(mtv1);  
  113.             shakeAnimation(mtv2);  
  114.             shakeAnimation(mtv3);  
  115.             shakeAnimation(mtv4);  
  116.             shakeAnimation(mtv5);  
  117.             shakeAnimation(mtv6);  
  118.             shakeAnimation(mtv7);  
  119.             shakeAnimation(mtv8);  
  120.             shakeAnimation(mtv9);  
  121.             shakeAnimation(mtv10);  
  122.             shakeAnimation(mtv11);  
  123.             shakeAnimation(mtv12);  
  124.             shakeAnimation(mtv13);  
  125.             shakeAnimation(mtv14);  
  126.             shakeAnimation(mtv15);  
  127.             shakeAnimation(mtv16);  
  128.             shakeAnimation(mtv17);  
  129.             shakeAnimation(mtv18);  
  130.             shakeAnimation(mtv19);  

猜你喜欢

转载自blog.csdn.net/gfdhjf/article/details/84192211