码迷,mamicode.com
首页 > 移动开发 > 详细

android如何做iphone那种图片抖动动画的效果(包括button和EditText)

时间:2014-07-10 22:47:01      阅读:319      评论:0      收藏:0      [点我收藏+]

标签:android抖动动画

给按钮做抖动效果,可以这样做,建立anim文件夹在res下面,创建一个button_shake.xml

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="120"
    android:fromDegrees="-3"
    android:pivotX="100%"
    android:pivotY="100%"
    android:repeatCount="infinite"
    android:repeatMode="reverse"
    android:toDegrees="3" />

在代码里加载:

		final ImageButton button = (ImageButton) findViewById(R.id.btn);
		button.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Animation shake = AnimationUtils.loadAnimation(AnimationTest.this, R.anim.button_shake);
				shake.reset();
				shake.setFillAfter(true);
				button.startAnimation(shake);
			}
		});

给EditText做一个横向抖动的效果:

这样写anim的文件:

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android" 
android:fromXDelta="0" 
android:toXDelta="10" 
android:duration="1300" 
android:interpolator="@anim/cycle" />

cycle.xml主要描述动画的加速器:

<?xml version="1.0" encoding="utf-8"?>
<!-- 动画从开始到结束,变化率是循环给定次数的正弦曲线。
 -->
<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android" 
android:cycles="20" />

代码可以这样加载:

	final Button confirm = (Button) findViewById(R.id.btn_confirm);
		confirm.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if(custom_edittext.getText().toString().equals("jake")){
					Toast.makeText(AnimationTest.this, "welcome", Toast.LENGTH_LONG).show();
				}else{
					Animation shake = AnimationUtils.loadAnimation(AnimationTest.this, R.anim.shake_x);
					custom_edittext.startAnimation(shake);
				}
			}
		});

代码可以在http://download.csdn.net/detail/baidu_nod/7616277下载

android如何做iphone那种图片抖动动画的效果(包括button和EditText),布布扣,bubuko.com

android如何做iphone那种图片抖动动画的效果(包括button和EditText)

标签:android抖动动画

原文地址:http://blog.csdn.net/baidu_nod/article/details/37655327

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!