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 ...
随机推荐
- c语言mysql api
原文:c语言mysql api 1.mysql_affected_rows() //返回上次UPDATE.DELETE或INSERT查询更改/删除/插入的行数. 2.mysql_ ...
- nginx 查看并发连接数
这里仅仅说一下用命令查看(也可配置页面) 通过查tcp连接数 1.netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]} ...
- Andorid类似Fragment更换布置方法
public void replaceRightView(View v) { int f = LinearLayout.LayoutParams.MATCH_PARENT; LinearLayout. ...
- Controller 的 Action 只接受 Ajax 请求
ASP.NET MVC 使 Controller 的 Action 只接受 Ajax 请求. 2014-08-27 14:19 by h82258652, 555 阅读, 2 评论, 收藏, 编辑 首 ...
- Restful WebApi开发实践
随笔分类 - Restful WebApi开发实践 C#对WebApi数据操作 摘要: ## 目标简化并统一程序获取WebApi对应实体数据的过程,方便对实体进行扩充.原理就是数据服务使用反射发现 ...
- Ibatis ISqlMapper工厂类案例
namespace Model{ public class MapperFactory { //声明一个ISqlMapper接口类型的数据映射器 _mapper,其初始值为null private s ...
- mvc+EF比较好的框架
个人看了传智播客的一位讲师搭建的框架感觉很好,就自己通过模仿划了一下很不讲究的类图来学习之间的关系(有些地方可能有自己理解不对的地方).很感激那位讲师,我会把这个框架用在我自己的项目中.
- PushSharp的使用
PushSharp的使用 最近做公司的一个项目.一旦数据库插入新的消息,就要通知服务器,将这些新的消息推送给苹果客户端,以前我们的项目中有人做过这个功能,无奈做的有点复杂,而且代码没注释,我压根就没看 ...
- Visual Studio 2013 IIS Explorer 停止调试继续访问站点
升级到2013后,在做调试的时候默认调试服务器是 IIS Explorer,当终止调试的时候再次访问调试站点时已经无法访问了.此时想预览一下感觉很不方便. 为了能够预览可以参考一下配置: Tools ...
- In C# 代码实现
SOLID 设计原则 In C# 代码实现 [S] Single Responsibility Principle (单一职责原则) 认为一个对象应该仅只有一个单一的职责 namespace Si ...