Pau*_*aul 2 animation android button
我已按照以下教程进行操作:
代码很好,直到我到达:
Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);
Run Code Online (Sandbox Code Playgroud)
看来 R.anim 不存在,eclipse 建议在 R 类型中创建一个字段或在 R 类型中创建一个常量。如果我错了,请纠正我,但我不认为这两者都是解决方案。
我正在运行 Google API、平台 2.2、API 8 - 我尝试过更高级别,但没有什么区别。我想要完成的只是点击按钮时摇动......
任何反馈表示赞赏,
谢谢
您需要创建摇动动画 xml 文件。它将驻留在
/res/anim/shake.xml
它看起来像这样:
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0" android:toXDelta="10" android:duration="1000"
android:interpolator="@anim/cycle_7" />
Run Code Online (Sandbox Code Playgroud)
然后,您还需要插值器(cycle_7.xml):
<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
android:cycles="7" />
Run Code Online (Sandbox Code Playgroud)
这些文件都可以在以下位置找到
/路径/到/android_sdk/samples/android-15/ApiDemos/res/anim