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>
Java乔晓松-android中的帧动画FrameByFrame的更多相关文章
- Java乔晓松-android中调用系统拍照功能并显示拍照的图片
android中调用系统拍照功能并显示拍照的图片 如果你是拍照完,利用onActivityResult获取data数据,把data数据转换成Bitmap数据,这样获取到的图片,是拍照的照片的缩略图 代 ...
- Java乔晓松-android中上传图片到服务器Tomcat(Struts2)
在做android开发的时候,有时你会用到图片的上传功能,在我的android项目中,我是选中图片,点击上传多张图片 android客户端上传图片部分的代码如下: package com.exampl ...
- Java乔晓松-android中获取图片的缩略图(解决OutOfMemoryError)内存溢出的Bug
由于android获取图片过大是会出现内存溢出的Bug 07-02 05:10:13.792: E/AndroidRuntime(6016): java.lang.OutOfMemoryError 解 ...
- Java乔晓松-android的四大组件之一Service(服务的绑定)
android的四大组件之一Service(服务的绑定) 怎么绑定服务,又怎么解除服务,代码如下: MainActivity.java源码: package com.example.lesson14_ ...
- Android中的帧动画与补间动画的使用
前言 在日常开发中,我们有时候须要一些好看的动画效果,这时能够充分利用Android提供的这几种动画来实现. Android提供了3种类型的动画: 补间动画:补间动画能够应用于View,让你能够定义一 ...
- Java时间间隔问题在Android中的使用
转载请注明出处:http://www.cnblogs.com/cnwutianhao/p/6606720.html 假设我们在做项目的时候,获取到了一段音频,也知道音频长度,那么我们想对音频做一些处理 ...
- Android简单逐帧动画Frame的实现(三)
android之动画(三)通过AnimationDrawable控制逐帧动画 android与逐帧动画: 效果图: 当我们点击按钮时,该图片会不停的旋转,当再次点击按钮时,会停止在当前的状态. ...
- Android简单逐帧动画Frame的实现(二)
Android简单逐帧动画Frame的实现 Android简单逐帧动画Frame的实现 1.逐帧动画 即是通过播放预先排序好的图片来实现动态的画面,感觉像是放电影. 2.实现步骤: 1. 在工程里 ...
- android中设置Animation 动画效果
在 Android 中, Animation 动画效果的实现可以通过两种方式进行实现,一种是 tweened animation 渐变动画,另一种是 frame by frame animation ...
随机推荐
- DB2建表语句
db2 => create table test (name char(8) not null primary key,depid smallint,pay bigint) DB20000I S ...
- php中echo(),print(),print_r()用法
原文 php中echo(),print(),print_r()用法 从我对echo(),print(),print_r()这个函数的理解是echo可输入字符串变量常量,print与echo差不多,但p ...
- each与list的用法
each与list的用法(PHP学习) 1.each的用法 先看API array each ( array &$array ) api里是这么描述的:each — 返回数组中当前的键/值对并 ...
- 开发者需要了解的WebKit
2013-3-22 22:37| 发布者: sxwgf| 查看: 575| 评论: 0|来自: infoq 摘要: Paul Irish是著名的前端开发工程师,同时他也是Chrome开发者关系团队成员 ...
- OpenWrt的UCI系统
http://wiki.openwrt.org/doc/uci UCI是Unified Configuration Interface的缩写,翻译成中文就是统一配置接口,用途就是为OpenWrt提供一 ...
- sqlclr返回数据集案例
----------------------------------------------返回一张表,但只有一条数据,最后一次设置的. [Microsoft.SqlServer.Server.Sql ...
- beanutils中jdbc
public class JDBCTest { // public static void main(String[] args) throws Exception {// Cla ...
- iOS后向兼容:如何发现过期接口
以4.3以下兼容性为例,在项目预编译头文件(xx.pch)中加入如下代码: #import <Availability.h> #define __AVAILABILITY_INTERNAL ...
- java 权限 部分截图
下载地址:http://download.csdn.net/detail/heyehuang/5857263
- Tomcat过滤器模拟
直接上代码Filter.java public interface Filter { //过滤器 public void doFilter(Request request,Response respo ...