Android之仿iphone抖动效果
转自:http://blog.csdn.net/long33long/article/details/7693671
布局文件:
<?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>
代码:
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;
}
}
}
资源下载:http://download.csdn.net/detail/long33long/4395746
Android之仿iphone抖动效果的更多相关文章
- Android实现仿qq侧边栏效果
最近从github上看到一个关于侧边栏的项目,模仿的是qq侧边栏. Github地址是https://github.com/SpecialCyCi/AndroidResideMenu ,这个项目是一个 ...
- 50个Android开发人员必备UI效果源码[转载]
50个Android开发人员必备UI效果源码[转载] http://blog.csdn.net/qq1059458376/article/details/8145497 Android 仿微信之主页面 ...
- [转载] 50个Android开发人员必备UI效果源码
好东西,多学习! Android 仿微信之主页面实现篇Android 仿微信之界面导航篇Android 高仿QQ 好友分组列表Android 高仿QQ 界面滑动效果Android 高仿QQ 登陆界面A ...
- android该怎么办iphone那种画面抖动的动画效果(含有button和EditText)
首先在效果图: 要做到抖动效果按钮,能够这样做.设定anim房源res以下.创建一个button_shake.xml <? xml version="1.0" encodin ...
- Android仿iPhone 滚轮控件 实现
Android_开发 实用滚轮效果选择数字http://blog.csdn.net/zhangtengyuan23/article/details/8653771 Android仿iPhone滚轮控件 ...
- Android仿IOS回弹效果 ScrollView回弹 总结
Android仿IOS回弹效果 ScrollView回弹 总结 应项目中的需求 须要仿IOS 下拉回弹的效果 , 我在网上搜了非常多 大多数都是拿scrollview 改吧改吧 试了一些 发现总 ...
- 通用的Android控件抖动效果实现
这个小程序的功能在实际的开发中会用到,比如:设置Button左右晃动,或者上下的晃动效果,下面就给出示例代码. 首先:要定义一个xml文件,命名为Shake [html] view plain cop ...
- Android 实现高仿iOS桌面效果之可拖动的GridView(上)
转载请标明出处:http://blog.csdn.net/sk719887916/article/details/40074663,作者:skay 最近项目中遇到一个LIstview的拖动效 ...
- 021 Android 查询已经导入到工程中的数据库+抖动效果
1.将数据库(.db)文件放入工程中 在project状态下,新建assets文件夹,并将数据库文件放入assets目录下. 注意:assets目录.java目录.res目录是同级的 new---&g ...
随机推荐
- 【LOJ】#2186. 「SDOI2015」道路修建
题解 就是线段树维护一下转移矩阵 分成两种情况,一种是前面有两个联通块,一种是前面有一个联通块 从一个联通块转移到一个联通块 也就是新加一列的三个边选其中两条即可 从一个联通块转移到两个联通块 不连竖 ...
- plsql oracle 使用教程
课程 一 PL/SQL 基本查询与排序 本课重点: 1.写SELECT语句进行数据库查询 2.进行数学运算 3.处理空值 4.使用别名ALIASES 5.连接列 6.在SQL PLUS中编辑缓冲,修改 ...
- Java Socket实战之一 单线程通信基础socket
现在做Java直接使用Socket的情况是越来越少,因为有很多的选择可选,比如说可以用spring,其中就可以支持很多种远程连接的操作,另外jboss的remoting也是不错的选择,还有Apache ...
- [转]c++优先队列(priority_queue)用法详解
既然是队列那么先要包含头文件#include <queue>, 他和queue不同的就在于我们可以自定义其中数据的优先级, 让优先级高的排在队列前面,优先出队 优先队列具有队列的所有特性, ...
- C# Socket异步实现消息发送--附带源码
前言 看了一百遍,不如动手写一遍. Socket这块使用不是特别熟悉,之前实现是公司有对应源码改改能用. 但是不理解实现的过程和步骤,然后最近有时间自己写个demo实现看看,熟悉熟悉Socket. 网 ...
- android 调试Installation failed with message INSTALL_FAILED_USER_RESTRICTED: Install canceled by user.
真机调试 遇到的问题 在使用真机调试的程序的时候出现了这个问题. 解决方法如下
- 压缩归档文件审查工具p7zip-full
压缩归档文件审查工具p7zip-full 在数字取证中,会遇到各种形式的压缩文件和归档文件.为了处理这些不同的文件,Kali Linux提供了专用工具p7zip-full.该工具支持各种格式的压缩 ...
- Nutch源码阅读进程5
看nutch的源码仿佛就是一场谍战片,而构成这精彩绝伦的谍战剧情的就是nutch的每一个从inject->generate->fetch->parse->update的环节,首 ...
- OpenVPN使用easy-rsa3吊销证书
cd /etc/easy-rsa ./easyrsa revoke targetkey(证书名) ./easyrsa gen-crl 其中gen-crl会生成一份吊销证书的名单,放在pki/crl.p ...
- Visual Studio 2019 preview中体验C# 8.0新语法
准备工作: Visual Studio 2019 Preview版本中并没有包含所有的C# 8.0的新功能,但目前也有一些可以试用了.在开始之前,需要进行入两项设置: 将Framework设置为.ne ...