1.使用属性动画
ViewPropertyAnimator.animate(webView).translationX(20).setInterpolator(new CycleInterpolator(4)).setDuration(500).start();
2.使用xml动画---网上搜到的
1.shake.xml
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0"
android:toXDelta="20"
android:duration="1000"
android:interpolator="@anim/cycle"
>
</translate>
2.cycle.xml
<?xml version="1.0" encoding="utf-8"?>
<cycleInterpolator
xmlns:android="http://schemas.android.com/apk/res/android"
android:cycles="3"
>
</cycleInterpolator>
3.代码实现
Animation shakeAnim = AnimationUtils.loadAnimation(this, R.anim.shake);
webView.startAnimation(shakeAnim);