android学习(十)晃动动画

来源:互联网 发布:lua 性能优化 编辑:程序博客网 时间:2024/05/23 19:14

http://blog.sina.com.cn/s/blog_6e322ce7010175fp.html


功能:是android空间出现晃动效果

知识:Animation,shake,rotate
代码:
//x轴晃动
Animation shake =AnimationUtils.loadAnimation(MainActivity.this,R.anim.shake_x);
btn_x.startAnimation(shake);
//x轴晃动
Animation shake =AnimationUtils.loadAnimation(MainActivity.this,R.anim.shake_y);
btn_y.startAnimation(shake);
//x轴晃动
Animation shake =AnimationUtils.loadAnimation(MainActivity.this,R.anim.rotate);
btn.startAnimation(shake);

shake_x.xml:
<?xml version="1.0"encoding="utf-8"?>
<translatexmlns:android="http://schemas.android.com/apk/res/android" 
android:fromXDelta="0" 
android:toXDelta="10" 
android:duration="1000" 
android:interpolator="@anim/cycle" />
shake_y.xml:
<?xml version="1.0"encoding="utf-8"?>
<translatexmlns:android="http://schemas.android.com/apk/res/android"
   android:duration="2000"
   android:fromYDelta="0"
   android:toYDelta="10" 
   android:interpolator="@anim/cycle"
    >

</translate>
rotate.xml:
<?xml version="1.0"encoding="utf-8"?>
    <rotatexmlns:android="http://schemas.android.com/apk/res/android"
          android:fromDegrees="0"
          android:toDegrees="-2"
          android:toYScale="0.0"
          android:pivotX="50%"
          android:pivotY="50%"
          android:duration="3000"
          android:interpolator="@anim/cycle"
/>

代码下载:ShakeDemo.rar
效果如图:
android学习(十)晃动动画

0 0