用Animation动画实现Android应用的欢迎界面
转载自:http://smallmaple.iteye.com/blog/1255120
欢迎界面实现有多种方法,目前了解的实现方法包括
1) Animation;
2) 线程实现;
3) Handle实现;
本例子讨论第一种方法,第二种目前已经了解,但是第三种还不了解。
虽然是转载,但是源代码不全也不详细,可能有些人还是看不到最终处理结果,
这个代码包含了所有的代码和xml文件。
1. 创建名为WelcomeDemo的项目,Activity的对应名称为WelcomeDemoActivity;
2. 在res下创建anim目录,并创建文件welcome_alpha.xml;
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="2000"
/>
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:startOffset="3000"
android:duration="3000"
/>
</set>
3. 在WelcomeDemoActivity.java下的代码如下:
package zcping.hello.Welcomedemo;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
public class WelcomeDemoActivity extends Activity implements AnimationListener {
/** Called when the activity is first created. */
private ImageView imageView = null;
private Animation alphaAnimation = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);
imageView = (ImageView)findViewById(R.id.welcome_image_view);
alphaAnimation = AnimationUtils.loadAnimation(this, R.anim.welcome_alpha);
alphaAnimation.setFillEnabled(true); //启动Fill保持
alphaAnimation.setFillAfter(true); //设置动画的最后一帧是保持在View上面
imageView.setAnimation(alphaAnimation);
alphaAnimation.setAnimationListener(this); //为动画设置监听
}
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
//动画结束时结束欢迎界面并转到软件的主界面
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
this.finish();
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
//在欢迎界面屏蔽BACK键
if(keyCode==KeyEvent.KEYCODE_BACK) {
return false;
}
return false;
}
}
4. 创建MainActiviy.java文件用于创建主程序,作为调用欢迎界面后的主程序。
package zcping.hello.Welcomedemo;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
5. 对应于MainActivity.java的XML文件如下main.xml;
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
</LinearLayout>
6. 对应于WelcomeDemoActivity.java的XML文件welcome.xml如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center_vertical|center_horizontal">
<ImageView
android:id="@+id/welcome_image_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/welcome"
/>
</LinearLayout>
7. 把欢迎界面welcome_image_view.png的图片放到drawable目录下。
运行结果如下:
源码可联系:QQ 99597951
用Animation动画实现Android应用的欢迎界面相关推荐
- 【Android 基础】Animation 动画介绍和实现
转载自:http://www.cnblogs.com/yc-755909659/p/4290114.html 1.Animation 动画类型 Android的animation由四种类型组成: XM ...
- 【Android 基础】Animation 动画介绍和实现(转载)
最近做了下这方面的研究,在博客园上找到了一片很好很详细的文章,于是转了一下.原地址是http://www.cnblogs.com/yc-755909659/p/4290114.html 1.Anima ...
- Animation动画概述和执行原理
动画入门和进阶文章列表: Animation动画概述和执行原理 Android动画之补间动画TweenAnimation Android动画之逐帧动画FrameAnimation Android动画之 ...
- Animation动画相关
本文出自http://wangstar.javaeye.com/blog/409115,感觉基础知识归纳得不错,就COPY下来方便查找. 动画效果编程基础--Android Animation ...
- android中设置Animation 动画效果
在 Android 中, Animation 动画效果的实现可以通过两种方式进行实现,一种是 tweened animation 渐变动画,另一种是 frame by frame animation ...
- Android Animation动画效果简介
AlphaAnimation 淡入淡出动画 <alpha>A fade-in or fade-out animation. Represents an AlphaAnimation. a ...
- Android动画开发——Animation动画效果
动画类型 Android的animation由四种类型组成 XML中 alpha 渐变透明度动画效果 scale 渐变尺寸伸缩动画效果 translate 画面转换位置移动动画效果 rotate 画面 ...
- Android Animation动画(很详细)
Animations 一.Animations介绍 Animations是一个实现android UI界面动画效果的API,Animations提供了一系列的动画效果,可以进行旋转.缩放.淡入淡出等, ...
- Android Property Animation动画
3.0以前,android支持两种动画模式,tween animation,frame animation,在android3.0中又引入了一个新的动画系统:property animation,这三 ...
最新文章
- iptables防火墙的基本配置
- Entity Framework 出现 此 ObjectContext 实例已释放,不可再用于需要连接的操作 的错误...
- 卡尔曼滤波器原理和matlab实现
- Java学习笔记3——集合框架
- 阿里巴巴Java开发手册——速读记录
- 本月与上月对比数据叫什么_动态轨控数据分析:2019-11
- Bluetooth篇 开发实例之六 蓝牙RSSI计算距离
- 应用架构步入“无服务器”时代 Serverless技术迎来新发展
- D 语言是否可作为入门级的编程语言?
- 什么是python基础教程-python基础教程之python是什么?概念解析
- 常用网络协议的端口号
- CADD课程学习(7)-- 模拟靶点和小分子相互作用 (半柔性对接 AutoDock)
- xampp配置虚拟主机的步骤
- python电影网络爬虫代码_Python爬虫——爬取豆瓣电影Top250代码实例
- 为新版本火狐安装去广告插件
- python基础_字典_列表_元组考试
- 大厂成熟Foc电机代码STM32f031C6. 把原先的原理图,给整理了
- Python:通过网络爬虫实现一个简易控制台音乐播放器
- 数据科学之matplotlib库
- openwrt各软件包对应功能_极路由 1 刷 openwrt记录
热门文章
- (006)网络编程,反射及其应用,MySQL数据库
- win10打开软件总是弹出用户帐户控制怎么办
- Kubernetes各版本对应支持的docker版本列表
- Ubuntu打开VirtualBox的VDI(Virtual Disk Image)文件
- vue组件之间传值的几种方式
- vue组件之间的传值的几种方法
- php 执行慢,怎么查询php哪执行得慢
- centos下unzip命令不可用
- flex array java_Flex中ArrayCollection 与java中的ArrayList互转
- WRF-hydro,WRF,WPS安装2