anim文件夾下創(chuàng)建倆文件如下:
1.anim_shake.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
? ? android:fromXDelta="0"
? ? android:toXDelta="50"
? ? android:duration="500"
? ? android:interpolator="@anim/cycle_7"
? ? />
2.cycle.xml
<?xml version="1.0" encoding="utf-8"?>
<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
? ? android:cycles="2"
? ? />
怎么用?
Animation shake = AnimationUtils.loadAnimation(this, R.anim.anim_shake);//加載動(dòng)畫資源文件
findViewById(R.id.tv_shake).startAnimation(shake);//給組件播放動(dòng)畫效
自己看效果去吧(只是左右抖動(dòng))