智慧北京:欢迎页面——进入动画效果的实现
发布时间
阅读量:
阅读量
实现效果:




——————————————————————WelcomeUI.java—————————————————————————————————————
package huaxa.it.zhihuidemo;
import android.R.anim;
import android.R.animator;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.widget.ImageView;
/** * @项目名: ZhiHuiDemo
* @包名: huaxa.it.zhihuidemo
* @类名: WelcomeUI
* @创建者: 黄夏莲
* @创建时间: 2016年10月3日 ,上午10:52:21
* * @描述: TODO
*/
public class WelcomeUI extends Activity
{
private static final int ANIMATION_DURATION = 1500; // 动画时长(ctrl+shift+x变成大写,+F对齐)
private View mRootView;
@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//去掉标题title
//requestWindowFeature(Window.FEATURE_NO_TITLE);
//去掉状态栏
//getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.welcome);
//初始化View
mRootView = findViewById(R.id.welcome_root);
// 1、旋转动画
RotateAnimation rotateAnimation = new RotateAnimation(0,// 起始角度
360,// 终止角度
Animation.RELATIVE_TO_SELF,//x相对位置
0.5f,//x中心点
Animation.RELATIVE_TO_SELF, //y相对位置
0.5f);//y中心点
rotateAnimation.setDuration(ANIMATION_DURATION);// 设置动画时长
rotateAnimation.setFillAfter(true);// 该方法用于设置一个动画效果执行完毕后,View对象保留在终止的位置
// 2、缩放动画(按照比例缩放)
ScaleAnimation scaleAnimation = new ScaleAnimation(0f,//x起始比例
1f,//x终止比例
0f,//y起始比例
1f,//y终止比例
Animation.RELATIVE_TO_SELF,//x相对位置
0.5f, //x中心点
Animation.RELATIVE_TO_SELF,//y相对位置
0.5f);//y中心点
scaleAnimation.setDuration(ANIMATION_DURATION);// 设置动画时长
scaleAnimation.setFillAfter(true);// 该方法用于设置一个动画效果执行完毕后,View对象保留在终止的位置
// 3、透明度动画
AlphaAnimation alphaAnimation = new AlphaAnimation(0,//起始透明度
1);//终止透明度
alphaAnimation.setDuration(ANIMATION_DURATION);// 设置动画时长
alphaAnimation.setFillAfter(true);// 该方法用于设置一个动画效果执行完毕后,View对象保留在终止的位置
//动画集合
AnimationSet set = new AnimationSet(false);//若为true需要设置set.setInterpolator(i)可以实现加速/减速缩放,弹跳等;Interpolator是一个接口
set.addAnimation(rotateAnimation);//旋转
set.addAnimation(scaleAnimation);//缩放
set.addAnimation(alphaAnimation);//透明度
//开始动画
mRootView.startAnimation(set);
}
}
————————————————————————————welcome.xml——————————————————————————————————
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/welcome_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/splash_bg_newyear"
tools:context=".WelcomeUI" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/splash_sheep_newyear" />
</RelativeLayout>
AndroidManifest.xml字段中设置 android:theme 属性为 基于Android系统提供的样式资源路径
全部评论 (0)
还没有任何评论哟~
