android主界面帧动画,Android开发(25)--framebyframe帧动画并实现启动界面到主界面的跳转...

Drawable animation可以加载Drawable资源实现帧动画。AnimationDrawable是实现Drawable animations的基本类。推荐用XML文件的方法实现Drawable动画,不推荐在代码中实现。这种XML文件存放在工程中res/drawable/目录下。XML文件的指令(即属性)为动画播放的顺序和时间间隔。

在XML文件中元素为根节点,节点定义了每一帧,表示一个drawable资源的帧和帧间隔。此XML文件必须写在res资源文件目录下的anim文件夹下,

下面是一个XML文件的实例:

framebyframe.xml

android:oneshot="false">

下面是StartActivity.java

package com.example.lesson18_framebyframe;

import android.app.Activity;

import android.content.Intent;

import android.graphics.drawable.AnimationDrawable;

import android.os.Bundle;

import android.os.Handler;

import android.view.Menu;

import android.widget.ImageView;

public class StartActivity extends Activity {

private ImageView imageView;

private AnimationDrawable animationDrawable;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_start);

//帧动画

imageView = (ImageView) findViewById(R.id.imageView1);

//第一种方式实现的动画

/*animationDrawable = (AnimationDrawable) getResources().getDrawable(R.anim.framebyframe);

imageView.setBackgroundDrawable(animationDrawable);*/

//第二种方式实现的动画

imageView.setBackgroundResource(R.anim.framebyframe);

animationDrawable = (AnimationDrawable) imageView.getBackground();

animationDrawable.start();

new Handler(){

public void handleMessage(android.os.Message msg) {

if(msg.what==1){

Intent intent = new Intent(StartActivity.this,NextActivity.class);

startActivity(intent);

}

};

}.sendEmptyMessageDelayed(1, 7000);

//animationDrawable.setOneShot(false);是否循环播放

//animationDrawable.stop();停止播放

//animationDrawable.isRunning();//是否播放

//animationDrawable.getNumberOfFrames();//播放帧

//animationDrawable.getFrame(index); 返回制定索引的 Drawable对象

//animationDrawable.getDuration(i);停留的时间

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.start, menu);

return true;

}

}

布局文件:

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=".StartActivity" >

android:id="@+id/imageView1"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_alignParentLeft="true" />

NextActivity.java

package com.example.lesson18_framebyframe;

import android.app.Activity;

import android.os.Bundle;

import android.widget.TextView;

public class NextActivity extends Activity {

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

TextView tv = new TextView(this);

tv.setText("启动界面到主界面完成");

setContentView(tv);

}

}

效果如下:

504db2192f715b98a86034b7d2073bec.png                8dc6acc241c57a3429d2853e0407e6f3.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值