先看效果后上代码:

动画开始----

动画切换的界面----

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

重要的方法:

                  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")@Overrideprotected 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() {@Overridepublic 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();}@Overridepublic 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 {@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.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>



更多相关文章

  1. Android的Launcher显示默认apk
  2. Android(安卓)RelativeLayout(7.1) 源码解析
  3. Android(安卓)Studio 第一次安装可能遇到的问题
  4. (转)Android动画学习笔记-Android(安卓)Animation
  5. 一起学android之设置ListView数据显示的动画效果(24)
  6. clickOnMenuItem应注意的
  7. Android(安卓)给Animation设置setRepeatMode不起作用
  8. Android源码个个击破之PackageManager
  9. Android(安卓)Studio&源码混淆配置及其调试注意事项

随机推荐

  1. AndroidX迁移
  2. android确定kernel使用的config文件
  3. 讨论会1:Android消息循环机制原理与实现
  4. Android控件TextView中ellipsize属性(设置
  5. Android(安卓)解析smi字幕
  6. Android 自定义Html标签
  7. 在android 6.0以上无法获取READ_PHONE_ST
  8. android在使用RecyclerView布局里的andro
  9. Android Wear 开发-创建第一个卡片
  10. android 实现QQ好友列表