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

来源:互联网 发布:linux下如何卸载jdk 编辑:程序博客网 时间:2024/06/05 06:37

由于标题栏会影响效果,某些页面需要设置没有上面的标题栏,在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.news;import android.app.Activity;import android.os.Bundle;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.RelativeLayout;public class SplashActivity extends Activity {private RelativeLayout rl_root;    @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();    }        /*     * 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);    //执行动画    rl_root.startAnimation(set);    }    }


0 0
原创粉丝点击