android 逐帧动画
16lz
2021-12-04
- <animation-listxmlns:android="http://schemas.android.com/apk/res/android"
- android:oneshot="false">
- <itemandroid:drawable="@drawable/main_frame_01"android:duration="100"/>
- <itemandroid:drawable="@drawable/main_frame_02"android:duration="100"/>
- <itemandroid:drawable="@drawable/main_frame_03"android:duration="100"/>
- <itemandroid:drawable="@drawable/main_frame_04"android:duration="100"/>
- <itemandroid:drawable="@drawable/main_frame_05"android:duration="100"/>
- <itemandroid:drawable="@drawable/main_frame_06"android:duration="100"/>
- <itemandroid:drawable="@drawable/main_frame_07"android:duration="100"/>
- <itemandroid:drawable="@drawable/main_frame_08"android:duration="100"/>
- <itemandroid:drawable="@drawable/main_frame_09"android:duration="100"/>
- <itemandroid:drawable="@drawable/main_frame_10"android:duration="100"/>
- <itemandroid:drawable="@drawable/main_frame_11"android:duration="100"/>
- <itemandroid:drawable="@drawable/main_frame_12"android:duration="100"/>
- <itemandroid:drawable="@drawable/main_frame_13"android:duration="100"/>
- <itemandroid:drawable="@drawable/main_frame_14"android:duration="100"/>
- <itemandroid:drawable="@drawable/main_frame_15"android:duration="100"/>
- <itemandroid:drawable="@drawable/main_frame_16"android:duration="100"/>
- <itemandroid:drawable="@drawable/main_frame_17"android:duration="100"/>
- <itemandroid:drawable="@drawable/main_frame_18"android:duration="100"/>
- <itemandroid:drawable="@drawable/main_frame_19"android:duration="100"/>
- </animation-list>
- publicvoidonCreate(BundlesavedInstanceState){
- super.onCreate(savedInstanceState);
- setContentView(R.layout.aaa);
- m_RunButton=(Button)this.findViewById(R.id.Button01);
- m_StopButton=(Button)this.findViewById(R.id.Button02);
- m_RunButton.setOnClickListener(m_BtnRunClickListener);
- m_StopButton.setOnClickListener(m_BtnStopClickListener);
- imgView=(ImageView)this.findViewById(R.id.ImageView01);
- imgView.setBackgroundResource(R.drawable.animation);
- mAnimation=(AnimationDrawable)imgView.getBackground();
- //startAnimation(mAnimation);
- }
onCreate 中 Animation 需要一个 view 所以 imgView.getBackground()返回一个view background 保证切换图片时不会重叠
animation.start() 不能写在onCreate中否则不能执行,可能系统调用view.invalidate()不能在onCreate调用的原因,否则会冲突```onCreate时
invalidate(废止)。把animation.start() 写在button的响应里。
[java] view plain copy- protectedvoidonResume(){
- //TODOAuto-generatedmethodstub
- super.onResume();
- //mHandler.postDelayed(mRunnable,START_DELAY);
- }
- privateView.OnClickListenerm_BtnRunClickListener=newView.OnClickListener()
- {
- publicvoidonClick(Viewarg0){
- //TODOAuto-generatedmethodstub
- startAnimation(mAnimation);
- }
- };
- privateView.OnClickListenerm_BtnStopClickListener=newView.OnClickListener()
- {
- publicvoidonClick(Viewarg0){
- //TODOAuto-generatedmethodstub
- stopAnimation(mAnimation);
- }
- };
- protectedvoidstartAnimation(finalAnimationDrawableanimation){
- if(animation!=null&&!animation.isRunning()){
- animation.run();
- }
- }
- protectedvoidstopAnimation(finalAnimationDrawableanimation){
- if(animation!=null&&animation.isRunning())animation.stop();
- }
原文地址: http://blog.csdn.net/wangyi_lin/article/details/6678473
更多相关文章
- 设置Android(安卓)app背景图片(Android(安卓)studio)
- Android的Actiovity组件
- Android(安卓)WebView与 JS 的交互方式
- android 使用Intent传递数据之全局变量传递
- android 使用Intent传递数据之全局变量传递
- android 实现自定义键盘的实例
- 处女男学Android(十四)---Android(安卓)重量级数据存储之SQLite
- Android的MediaPlayer架构介绍
- Android深入四大组件(一)应用程序启动过程