Android仿Iphone图标抖动效果
来源:互联网 发布:折800淘宝入驻条件 编辑:程序博客网 时间:2024/05/20 14:28
http://blog.csdn.net/long33long/article/details/7693671
最近闲来无聊,研究了一下IPhone桌面图标的抖动,网上有一个类似的事例,但是我看来效果实在不佳,自己也来写一个玩玩,当然代码很乱,杂乱无章,不满意的别骂我啊,当然也欢迎一起交流啊,嚯嚯
首先是JAVA代码ShakeTestActivity.java:
- package com.android.shake;
- import android.app.Activity;
- import android.os.Bundle;
- import android.util.DisplayMetrics;
- import android.view.animation.Animation;
- import android.view.animation.Animation.AnimationListener;
- import android.view.animation.RotateAnimation;
- import android.widget.TextView;
- import android.view.View;
- import android.view.Window;
- public class ShakeTestActivity extends Activity implements View.OnClickListener {
- private TextView mtv0;
- private TextView mtv1;
- private TextView mtv2;
- private TextView mtv3;
- private TextView mtv4;
- private TextView mtv5;
- private TextView mtv6;
- private TextView mtv7;
- private TextView mtv8;
- private TextView mtv9;
- private TextView mtv10;
- private TextView mtv11;
- private TextView mtv12;
- private TextView mtv13;
- private TextView mtv14;
- private TextView mtv15;
- private TextView mtv16;
- private TextView mtv17;
- private TextView mtv18;
- private TextView mtv19;
- private boolean mNeedShake = false;
- private boolean mStartShake = false;
- private static final int ICON_WIDTH = 80;
- private static final int ICON_HEIGHT = 94;
- private static final float DEGREE_0 = 1.8f;
- private static final float DEGREE_1 = -2.0f;
- private static final float DEGREE_2 = 2.0f;
- private static final float DEGREE_3 = -1.5f;
- private static final float DEGREE_4 = 1.5f;
- private static final int ANIMATION_DURATION = 80;
- private int mCount = 0;
- float mDensity;
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- setContentView(R.layout.main);
- DisplayMetrics dm = new DisplayMetrics();
- getWindowManager().getDefaultDisplay().getMetrics(dm);
- if (dm != null) {
- mDensity = dm.density;
- }
- mtv0 = (TextView) findViewById(R.id.tv0);
- mtv0.setOnClickListener(this);
- mtv1 = (TextView) findViewById(R.id.tv1);
- mtv1.setOnClickListener(this);
- mtv2 = (TextView) findViewById(R.id.tv2);
- mtv2.setOnClickListener(this);
- mtv3 = (TextView) findViewById(R.id.tv3);
- mtv3.setOnClickListener(this);
- mtv4 = (TextView) findViewById(R.id.tv4);
- mtv4.setOnClickListener(this);
- mtv5 = (TextView) findViewById(R.id.tv5);
- mtv5.setOnClickListener(this);
- mtv6 = (TextView) findViewById(R.id.tv6);
- mtv6.setOnClickListener(this);
- mtv7 = (TextView) findViewById(R.id.tv7);
- mtv7.setOnClickListener(this);
- mtv8 = (TextView) findViewById(R.id.tv8);
- mtv8.setOnClickListener(this);
- mtv9 = (TextView) findViewById(R.id.tv9);
- mtv9.setOnClickListener(this);
- mtv10 = (TextView) findViewById(R.id.tv10);
- mtv10.setOnClickListener(this);
- mtv11 = (TextView) findViewById(R.id.tv11);
- mtv11.setOnClickListener(this);
- mtv12 = (TextView) findViewById(R.id.tv12);
- mtv12.setOnClickListener(this);
- mtv13 = (TextView) findViewById(R.id.tv13);
- mtv13.setOnClickListener(this);
- mtv14 = (TextView) findViewById(R.id.tv14);
- mtv14.setOnClickListener(this);
- mtv15 = (TextView) findViewById(R.id.tv15);
- mtv15.setOnClickListener(this);
- mtv16 = (TextView) findViewById(R.id.tv16);
- mtv16.setOnClickListener(this);
- mtv17 = (TextView) findViewById(R.id.tv17);
- mtv17.setOnClickListener(this);
- mtv18 = (TextView) findViewById(R.id.tv18);
- mtv18.setOnClickListener(this);
- mtv19 = (TextView) findViewById(R.id.tv19);
- mtv19.setOnClickListener(this);
- }
- @Override
- public void onClick(View v) {
- if (!mStartShake) {
- mStartShake = true;
- mNeedShake = true;
- shakeAnimation(mtv0);
- shakeAnimation(mtv1);
- shakeAnimation(mtv2);
- shakeAnimation(mtv3);
- shakeAnimation(mtv4);
- shakeAnimation(mtv5);
- shakeAnimation(mtv6);
- shakeAnimation(mtv7);
- shakeAnimation(mtv8);
- shakeAnimation(mtv9);
- shakeAnimation(mtv10);
- shakeAnimation(mtv11);
- shakeAnimation(mtv12);
- shakeAnimation(mtv13);
- shakeAnimation(mtv14);
- shakeAnimation(mtv15);
- shakeAnimation(mtv16);
- shakeAnimation(mtv17);
- shakeAnimation(mtv18);
- shakeAnimation(mtv19);
- }
- }
- private void shakeAnimation(final View v) {
- float rotate = 0;
- int c = mCount++ % 5;
- if (c == 0) {
- rotate = DEGREE_0;
- } else if (c == 1) {
- rotate = DEGREE_1;
- } else if (c == 2) {
- rotate = DEGREE_2;
- } else if (c == 3) {
- rotate = DEGREE_3;
- } else {
- rotate = DEGREE_4;
- }
- final RotateAnimation mra = new RotateAnimation(rotate, -rotate, ICON_WIDTH * mDensity / 2, ICON_HEIGHT * mDensity / 2);
- final RotateAnimation mrb = new RotateAnimation(-rotate, rotate, ICON_WIDTH * mDensity / 2, ICON_HEIGHT * mDensity / 2);
- mra.setDuration(ANIMATION_DURATION);
- mrb.setDuration(ANIMATION_DURATION);
- mra.setAnimationListener(new AnimationListener() {
- @Override
- public void onAnimationEnd(Animation animation) {
- if (mNeedShake) {
- mra.reset();
- v.startAnimation(mrb);
- }
- }
- @Override
- public void onAnimationRepeat(Animation animation) {
- }
- @Override
- public void onAnimationStart(Animation animation) {
- }
- });
- mrb.setAnimationListener(new AnimationListener() {
- @Override
- public void onAnimationEnd(Animation animation) {
- if (mNeedShake) {
- mrb.reset();
- v.startAnimation(mra);
- }
- }
- @Override
- public void onAnimationRepeat(Animation animation) {
- }
- @Override
- public void onAnimationStart(Animation animation) {
- }
- });
- v.startAnimation(mra);
- }
- @Override
- public void onBackPressed() {
- if (!mNeedShake) {
- super.onBackPressed();
- } else {
- mNeedShake = false;
- mCount = 0;
- mStartShake = false;
- }
- }
- }
然后是main.xml文件
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical" >
- <LinearLayout
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
- <TextView
- android:id="@+id/tv0"
- android:layout_width="80dip"
- android:layout_height="94dip"
- android:drawableTop="@drawable/ic_launcher"
- android:text="@string/hello" />
- <TextView
- android:id="@+id/tv1"
- android:layout_width="80dip"
- android:layout_height="94dip"
- android:drawableTop="@drawable/ic_launcher"
- android:text="@string/hello" />
- <TextView
- android:id="@+id/tv2"
- android:layout_width="80dip"
- android:layout_height="94dip"
- android:drawableTop="@drawable/ic_launcher"
- android:text="@string/hello" />
- <TextView
- android:id="@+id/tv3"
- android:layout_width="80dip"
- android:layout_height="94dip"
- android:drawableTop="@drawable/ic_launcher"
- android:text="@string/hello" />
- </LinearLayout>
- <LinearLayout
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
- <TextView
- android:id="@+id/tv4"
- android:layout_width="80dip"
- android:layout_height="94dip"
- android:drawableTop="@drawable/ic_launcher"
- android:text="@string/hello" />
- <TextView
- android:id="@+id/tv5"
- android:layout_width="80dip"
- android:layout_height="94dip"
- android:drawableTop="@drawable/ic_launcher"
- android:text="@string/hello" />
- <TextView
- android:id="@+id/tv6"
- android:layout_width="80dip"
- android:layout_height="94dip"
- android:drawableTop="@drawable/ic_launcher"
- android:text="@string/hello" />
- <TextView
- android:id="@+id/tv7"
- android:layout_width="80dip"
- android:layout_height="94dip"
- android:drawableTop="@drawable/ic_launcher"
- android:text="@string/hello" />
- </LinearLayout>
- <LinearLayout
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
- <TextView
- android:id="@+id/tv8"
- android:layout_width="80dip"
- android:layout_height="94dip"
- android:drawableTop="@drawable/ic_launcher"
- android:text="@string/hello" />
- <TextView
- android:id="@+id/tv9"
- android:layout_width="80dip"
- android:layout_height="94dip"
- android:drawableTop="@drawable/ic_launcher"
- android:text="@string/hello" />
- <TextView
- android:id="@+id/tv10"
- android:layout_width="80dip"
- android:layout_height="94dip"
- android:drawableTop="@drawable/ic_launcher"
- android:text="@string/hello" />
- <TextView
- android:id="@+id/tv11"
- android:layout_width="80dip"
- android:layout_height="94dip"
- android:drawableTop="@drawable/ic_launcher"
- android:text="@string/hello" />
- </LinearLayout>
- <LinearLayout
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
- <TextView
- android:id="@+id/tv12"
- android:layout_width="80dip"
- android:layout_height="94dip"
- android:drawableTop="@drawable/ic_launcher"
- android:text="@string/hello" />
- <TextView
- android:id="@+id/tv13"
- android:layout_width="80dip"
- android:layout_height="94dip"
- android:drawableTop="@drawable/ic_launcher"
- android:text="@string/hello" />
- <TextView
- android:id="@+id/tv14"
- android:layout_width="80dip"
- android:layout_height="94dip"
- android:drawableTop="@drawable/ic_launcher"
- android:text="@string/hello" />
- <TextView
- android:id="@+id/tv15"
- android:layout_width="80dip"
- android:layout_height="94dip"
- android:drawableTop="@drawable/ic_launcher"
- android:text="@string/hello" />
- </LinearLayout>
- <LinearLayout
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
- <TextView
- android:id="@+id/tv16"
- android:layout_width="80dip"
- android:layout_height="94dip"
- android:drawableTop="@drawable/ic_launcher"
- android:text="@string/hello" />
- <TextView
- android:id="@+id/tv17"
- android:layout_width="80dip"
- android:layout_height="94dip"
- android:drawableTop="@drawable/ic_launcher"
- android:text="@string/hello" />
- <TextView
- android:id="@+id/tv18"
- android:layout_width="80dip"
- android:layout_height="94dip"
- android:drawableTop="@drawable/ic_launcher"
- android:text="@string/hello" />
- <TextView
- android:id="@+id/tv19"
- android:layout_width="80dip"
- android:layout_height="94dip"
- android:drawableTop="@drawable/ic_launcher"
- android:text="@string/hello" />
- </LinearLayout>
- </LinearLayout>
string.xml
- <?xml version="1.0" encoding="utf-8"?>
- <resources>
- <string name="hello">Hello World</string>
- <string name="app_name">ShakeTest</string>
- </resources>
测试机的分辨率是320x480,640x960,其他分辨率显示效果不佳自行调整吧
附截图一张:
资源下载:http://download.csdn.net/detail/long33long/4395746
- Android仿Iphone图标抖动效果
- Android仿Iphone图标抖动效果
- Android仿Iphone图标抖动效果
- 仿iOS图标抖动
- android 中的抖动效果(仿苹果)
- 仿iOS图标抖动、iOS删除App效果
- javascript 仿iphone手机输入密码错误时抖动效果
- Android仿QQ窗口的抖动的动画效果
- Android仿QQ窗口的抖动的动画效果
- Android 仿IOS解锁锁屏文字抖动效果
- Android-仿iPhone滚轮控件效果
- android 仿Iphone底部 tab效果
- android 仿iphone的tab效果
- android-仿iphone滚轮控件效果
- Android-仿iPhone滚轮控件效果
- android 仿iphone 密码错误震动效果
- 模拟长按图标,图标抖动效果
- android实现抖动效果
- vs2010每次build都会重新编译链接解决办法
- 西南石油大学第三届信息安全大赛--基础1
- dsp学习资料之三
- 关于SIGPIPE信号
- 云计算将如何彻底改变世界
- Android仿Iphone图标抖动效果
- OSGI 体系结构及Bundle简介
- 七 redis学习笔记之持久化
- 请自己写出strcpy函数
- QT中由图形生成SVG文件实现方案
- smarty中变量调节器
- 数据库中数据增删查改可能的级联操作
- android BitmapFactory的OutOfMemoryError: bitmap size exceeds VM budget解决..
- 八 redis学习笔记之主从复制