`
scliu0718
  • 浏览: 51486 次
  • 性别: Icon_minigender_1
  • 来自: 成都
文章分类
社区版块
存档分类
最新评论

Android实现抖动动画

 
阅读更多

使用动画让控件实现抖动,其实就是让横移(可心混合其它类型旋转等一起)的动画循环播放,使用Interpolator类来实现。

原理很简单,不多说了,代码如下:


Activity代码:

		this.btn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				 TextView yearAndMouth = (TextView) JGWorkLogDateAndOperaPanel.this.findViewById(R.id.year_mounth_text);
				 Animation cycleAnim = AnimationUtils.loadAnimation(context, R.anim.img_anim);
				 yearAndMouth.startAnimation(cycleAnim);
			}
		});

imag_anim.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <translate
        android:duration="100"
        android:fromYDelta="0"
        android:toYDelta="500"
        android:fromXDelta="0"
        android:toXDelta="1"
        android:repeatCount="5"
        android:repeatMode="restart"
        android:interpolator="@anim/cylce" />
    <rotate 
        android:duration="300"
        android:pivotX="100%p"
        android:pivotY="100%p"
        android:fromDegrees="90"
        android:interpolator="@anim/cylce" />

</set>

cylce.xml

<?xml version="1.0" encoding="utf-8"?>
<!--
官方解析 动画循环加速器:
——AccelerateInterpolator:动画从开始到结束,变化率是一个加速的过程。
——DecelerateInterpolator:动画从开始到结束,变化率是一个减速的过程。
——CycleInterpolator:动画从开始到结束,变化率是循环给定次数的正弦曲线。
——AccelerateDecelerateInterpolator:动画从开始到结束,变化率是先加速后减速的过程。
——LinearInterpolator:动画从开始到结束,变化率是线性变化。

-->
<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
    android:cycles="5" />


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics