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 ...
随机推荐
- 原生AJAX基础讲解及兼容处理
原文:原生AJAX基础讲解及兼容处理 AJAX = Asynchronous JavaScript and XML (异步的JavaScript和XML). AJAX不是新技术 ,但却是热门的技术.它 ...
- 快速构建Windows 8风格应用11-语义缩放
原文:快速构建Windows 8风格应用11-语义缩放 本篇博文主要介绍为什么需要语义缩放.什么是语义缩放.如何构建语义缩放. 为什么需要语义缩放 如果用过Windows 8系统的开发者都知道在Win ...
- gtest框架
解析gtest框架运行机制 1.前言 Google test是一款开源的白盒单元测试框架,据说目前在Google内部已在几千个项目中应用了基于该框架的白盒测试. 最近的工作是在搞一个基于gtest ...
- 移动端App混合开发问题 汇总
1.IOS系统,双击页面,页面会向上移动一节,无法滑动复原. //阻止用户双击放大 var agent = navigator.userAgent.toLowerCase(); //检测是否是ios ...
- 使用Vim或Codeblocks格式化代码
在网上的代码,有很多的代码都是丢失缩进的,几行还好,手动改改,多了呢,不敢想象,没有缩进的代码.别说排错,就是阅读都是困难的,还好,有两个常用工具可以轻松的解决问题. (一)Vim(简单方便,可将代码 ...
- [译]JDK 6 and JDK 7中的subString()方法
(说明,该文章翻译自The substring() Method in JDK 6 and JDK 7) 在JDK 6 and JDK 7中的substring(int beginIndex, int ...
- 数据类型 text 和 varchar 在 add 运算符中不兼容
原文:数据类型 text 和 varchar 在 add 运算符中不兼容 在SQL Server2005中,使用类似下面的Update语句: 1 UPDATE tb_SmsBlacklist SET ...
- C#泛型回顾点滴
前言 C#的泛型一直是学习者津津乐道的课题了,这确实是一个非常有用的特性,不过在实际使用中,还是有很多需要注意的地方,我们需要通过自己动手实践以及结合理论进行理解,最终总结出自己的编码规范和最佳实践 ...
- sql之T-SQL
sql之T-SQL 下面就T-SQL的几个方面来分别讲解一下. 1.变量 要动态的写sql语句,就不能没有变量. 声明变量并赋值: 1 declare @i as int;--定义一个 int 类 ...
- ssh配置公钥和私钥登陆SecureCRT
在用windows时管理linux服务器时,常会用到SecureCRT.Xshell以及开源的putty.在我工作环境大多都是采用密码认证的方式进行登录.今天对学习了些SecureCRT的密钥登录方式 ...