Frame Animation帧播放动画
16lz
2021-01-23
<?xml version="1.0" encoding="utf-8"?><animation-list android:id="@+id/handimation" android:oneshot="false" xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/a1" android:duration="150" /> <item android:drawable="@drawable/icon" android:duration="150" /> <item android:drawable="@drawable/stat_sad" android:duration="150" /> </animation-list>
将上面的代码加入res/anim/rocket_thrust.xml
然后在代码中:
ImageView rocketImage = (ImageView) findViewById(R.id.rocket_image); rocketImage.setBackgroundDrawable(getResources().getDrawable(R.drawable.rocket_thrust)); rocketAnimation = (AnimationDrawable) rocketImage.getBackground();
或者
rocketImage.setBackgroundResource(R.anim.rocket_thrust);
rocketAnimation = (AnimationDrawable) rocketImage.getBackground();
如果用TweenAniamation动画 你的用
rocketImage.setAnimation(AnimationUtils.loadAnimation(this, R.anim.rocket_thrust) );
同时还要注意 你的图画不能是黑白的 这样看不出效果,因为屏幕是黑色的 我就因为这个原因 还以为代码错误
然后就是运动
@Override public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { ((AnimationDrawable) rocketAnimation).start(); return true; } return super.onTouchEvent(event); }
在这里没有弄出自动播放 我也没找到原因
更多相关文章
- Android 代码改变图片颜色android:tint="@color/main_color" and
- Kotlin 写 Android 单元测试(四),Robolectric 在 JVM 上测试安卓相
- 修改 framework 代码的经验和踩过的坑
- android常用颜色代码定义
- android 代码proguard
- Android日志系统分析之日志设备驱动程序代码阅读