Android achieves a shaking effect similar to that of Douyin privacy agreement when it is not read

 

Principle:
Implemented using animation

1. Create a translate animation file under the res-anmi folder

2. Use AnimationUtils to load the animation

shake_checkbox.xml

<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="300"
    android:fromXDelta="0"
    android:interpolator="@anim/shake_interpolator"
    android:toXDelta="30">
</translate>

The interpolator inside:

shake_interpolator.xml

<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
    android:cycles="2"><!--    抖动次数-->
</cycleInterpolator>

use:
 

                val loadAnimation = AnimationUtils.loadAnimation(this, R.anim.shake_checkbox)
                login_agreement_rl.startAnimation(loadAnimation)
login_agreement_rl is the control to shake

Guess you like

Origin blog.csdn.net/NewActivity/article/details/123431708