151.n1-splash页面,多种特效叠加

由于标题栏会影响效果,某些页面需要设置没有上面的标题栏,在activity中设置是对某一个activity有效,在application中设置是对所有的activity有效

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.ldw.news.SplashActivity"
            android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
动画特效有三种如下:

- 旋转 RotateAnimation
- 缩放 ScaleAnimation
- 渐变 AlphaAnimation

实现如下:

布局文件activity_splash.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:id="@+id/rl_root"
    android:background="@drawable/splash_bg_newyear" >

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/splash_horse_newyear"
         />

</RelativeLayout>

逻辑文件SplashActivity.java

package com.ldw.beijing;

import com.ldw.beijing.utils.PreferencesUtils;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.widget.RelativeLayout;

public class SplashActivity extends Activity {

	private RelativeLayout rl_root;
	private SharedPreferences sp;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        
        //获取到splash页面的总布局
        rl_root = (RelativeLayout) findViewById(R.id.rl_root);
        
        //spalsh进入图片的旋转动画
        startAnimation();
        
       // LibUtils.doFun();
    }
    
    /*
     * spalsh的动画
     */
    private void startAnimation(){
    	//创建一个AnimationSet来支持多种动画特效
    	AnimationSet set = new AnimationSet(false);
    	
    	
    	//前两个参数是旋转的角度,后四个参数是相对于自己的中心
    	RotateAnimation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
    	//动画维持时间
    	rotateAnimation.setDuration(3000);
    	//保持最后的状态
    	rotateAnimation.setFillAfter(true);
    	
    	//旋转的过程中大小会变化
    	ScaleAnimation scaleAnimation = new ScaleAnimation(0, 1, 0, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
    	//动画维持时间
    	scaleAnimation.setDuration(3000);
    	//保持最后的状态
    	scaleAnimation.setFillAfter(true);
    	
    	//参数为透明值由不透明到完全透明
    	AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1);
    	//动画维持时间
    	alphaAnimation.setDuration(3000);
    	//保持最后的状态
    	alphaAnimation.setFillAfter(true);
    	
    	//set集合中添加多个动画特效
    	set.addAnimation(scaleAnimation);
    	set.addAnimation(rotateAnimation);
    	set.addAnimation(alphaAnimation);
    	
    	//设置动画监听,动画结束以后跳转aactivity
    	set.setAnimationListener(new AnimationListener(){

			@Override
			public void onAnimationStart(Animation animation) {
				// TODO Auto-generated method stub
				
			}
			
			//动画执行结束
			@Override
			public void onAnimationEnd(Animation animation) {
				//页面的跳转
				jumpNextPage();
				
			}

			@Override
			public void onAnimationRepeat(Animation animation) {
				// TODO Auto-generated method stub
				
			}
    		
    	});
    	//执行动画
    	rl_root.startAnimation(set);
    }
    
    /*
     * 页面的跳转
     */
    private void jumpNextPage(){
    	/*使用封装实现
    	//判断是不是第一次进入引导页
    	sp = getSharedPreferences("config", MODE_PRIVATE);
    	boolean userGuide = sp.getBoolean("is_first_userGuide", false);
    	*/
    	boolean userGuide = PreferencesUtils.getBoolean(this, "is_first_userGuide", false);
    	//第一次进入的时候显示引导页
    	if(!userGuide){
	    	//跳转到引导页
			startActivity(new Intent(SplashActivity.this, GuideActivity.class));
			
    	}else{
    		startActivity(new Intent(SplashActivity.this, MainActivity.class));

    	}
    	finish();
    }
    
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值