zoukankan      html  css  js  c++  java
  • Java乔晓松-android中的帧动画FrameByFrame

    先看效果后上代码:

    动画开始----

    动画切换的界面----

    动画播放完毕后的跳转界面-----

    重要的方法:

                      imageView.setBackgroundResource(R.anim.framebyframe);
    		
    		animationDrawable = (AnimationDrawable) imageView.getBackground();
    		// 设置是否循环播放,false是循环播放,true只播放一遍
    		// animationDrawable.setOneShot(false);
    		animationDrawable.start();
    //animationDrawable.setOneShot(false);是否循环播放
      //animationDrawable.stop();停止播放
      //animationDrawable.isRunning();//是否播放
      //animationDrawable.getNumberOfFrames();//播放帧
      //animationDrawable.getFrame(index); 返回制定索引的 Drawable对象
      //animationDrawable.getDuration(i);停留的时间

    项目的开发结构:

    完整代码:

    SplashActivity.java源码:

    package com.example.lesson18_framebyframe;
    
    import android.annotation.SuppressLint;
    import android.app.Activity;
    import android.content.Intent;
    import android.graphics.drawable.AnimationDrawable;
    import android.os.Bundle;
    import android.os.Handler;
    import android.os.Message;
    import android.view.Menu;
    import android.widget.ImageView;
    
    /**
     * 2013-6-27 下午3:41:20
     * 
     * @author 乔晓松
     */
    public class SplashActivity extends Activity {
    
    	private ImageView imageView;
    	private AnimationDrawable animationDrawable;
    
    	@SuppressLint("HandlerLeak")
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.activity_main);
    
    		imageView = (ImageView) findViewById(R.id.imageView1);
    		imageView.setBackgroundResource(R.anim.framebyframe);
    		
    		animationDrawable = (AnimationDrawable) imageView.getBackground();
    		// 设置是否循环播放,false是循环播放,true只播放一遍
    		// animationDrawable.setOneShot(false);
    		animationDrawable.start();
    		new Handler() {
    			@Override
    			public void handleMessage(Message msg) {
    				super.handleMessage(msg);
    				if (msg.what == 1) {
    					Intent intent = new Intent(SplashActivity.this,
    							MainActivity.class);
    					startActivity(intent);
    
    					SplashActivity.this.finish();
    				}
    			}
    		}.sendEmptyMessageDelayed(1, 3000);
    		// this.finish();
    	}
    
    	@Override
    	public boolean onCreateOptionsMenu(Menu menu) {
    		// Inflate the menu; this adds items to the action bar if it is present.
    		getMenuInflater().inflate(R.menu.main, menu);
    		return true;
    	}
    }
    



    framebyframe.xml源码

    <animation-list xmlns:android="http://schemas.android.com/apk/res/android"
        android:oneshot="true" >
    
        <item
            android:drawable="@drawable/span"
            android:duration="1000"/>
        <item
            android:drawable="@drawable/span1"
            android:duration="1000"/>
        <item
            android:drawable="@drawable/psbpan"
            android:duration="1000"/>
        <item
            android:drawable="@drawable/ic_launcher"
            android:duration="1000"/>
    
    </animation-list>


    MainActivity.java源码:

    package com.example.lesson18_framebyframe;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.widget.TextView;
    
    /**
     * 2013-6-27 下午3:46:39
     * 
     * @author 乔晓松
     */
    public class MainActivity extends Activity {
    
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		// TODO Auto-generated method stub
    		super.onCreate(savedInstanceState);
    		TextView tv = new TextView(this);
    		tv.setText("主页面");
    		this.setContentView(tv);
    	}
    }
    


    layout-main.xml布局文件:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".MainActivity" >
    
        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            tools:ignore="ContentDescription" />
    
    </RelativeLayout>
    

    清单文件:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.lesson18_framebyframe"
        android:versionCode="1"
        android:versionName="1.0" >
    
        <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="17" />
    
        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name="com.example.lesson18_framebyframe.SplashActivity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity android:name="com.example.lesson18_framebyframe.MainActivity" >
            </activity>
        </application>
    
    </manifest>



     

  • 相关阅读:
    软件測试培训笔记
    spring test---測试SpringMvc初识
    第1章第3节 线性表的比較
    Remove Duplicates from Sorted List leetcode
    泛型
    我的改进版2048(1)
    docker镜像和加速
    在 Azure Web 应用中创建 PHP 应用程序
    使用 Azure 门户创建 Windows 虚拟机
    使用 Azure 门户创建 Linux 虚拟机
  • 原文地址:https://www.cnblogs.com/jiangu66/p/3161368.html
Copyright © 2011-2022 走看看