`
独尊孤鹰
  • 浏览: 8776 次
  • 性别: Icon_minigender_2
  • 来自: 北京
社区版块
存档分类
最新评论

Android学习---shake效果的实现

阅读更多
在Android\android-sdk-20120129\samples\android-8\ApiDemos下面实现了此效果


实现此效果需要两个XML文件cycle.xml和shake.xml
cycle.xml内容如下:
<?xml version="1.0" encoding="utf-8"?>
<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
    android:cycles="5" />
其中cycles的属性代表震动的快慢
shake.xml内容如下:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="1000"
    android:fromXDelta="0"
    android:interpolator="@anim/cycle"
    android:toXDelta="10" />
其中from和to的属性代表振幅了,duration代表震动持续时间,然后interpolator属性引用了cycle.xml文件。
然后就是代码中的使用了。
下面是核心代码
Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);
findViewById(R.id.login).startAnimation(shake);
通过AnimationUtils.loadAnimation创建一个Animation,然后要实现这个Animation的View只需要startAnimation即可。


原文来自:http://blog.sina.com.cn/s/blog_644f008a0101bt2t.html
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics