Android 电话抖动动画
时间: 2023-06-25 22:05:07 浏览: 47
Android 电话抖动动画可以通过使用帧动画实现以下是一个简单的实现过程:
1. 在drawable文件夹下创建一个xml文件,例如shake.xml:
```
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/phone_shake_1" android:duration="100" />
<item android:drawable="@drawable/phone_shake_2" android:duration="100" />
<item android:drawable="@drawable/phone_shake_3" android:duration="100" />
<item android:drawable="@drawable/phone_shake_4" android:duration="100" />
<item android:drawable="@drawable/phone_shake_5" android:duration="100" />
<item android:drawable="@drawable/phone_shake_6" android:duration="100" />
</animation-list>
```
2. 创建一个AnimationDrawable对象并将其设置为ImageView的背景:
```
ImageView imageView = findViewById(R.id.image_view);
AnimationDrawable animation = (AnimationDrawable) getResources().getDrawable(R.drawable.shake);
imageView.setBackground(animation);
```
3. 在需要抖动的时候,调用AnimationDrawable的start方法开始动画:
```
animation.start();
```
这样就可以实现一个简单的电话抖动动画了。当然,你也可以根据自己的需求修改动画的帧数、每一帧的持续时间等参数。