android啓動頁面製作

Android的啓動界面,製作起來十分容易,我們在使用過程中經常可以看到有個啓動效果,通常是一張廣告圖沒加上旋轉,縮放和漸變的特效。

更多支持可以訪問我的個人網站: https://www.cjluzzl.cn

首先你需要準備一張圖,我這裏隨便找了一張王者榮耀的截圖



整個項目的結構圖


然後寫一個佈局文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:id="@+id/rl_root"
    >

    <ImageView
        
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/index"
        />
</RelativeLayout>

回到Activity
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 startFlashActivity extends Activity {

    RelativeLayout rlRoot;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_startflash);
        //找到佈局
        rlRoot = (RelativeLayout) findViewById(R.id.rl_root);

        startFlash();


    }
    /**
     * 開始動畫
     */

    private void startFlash(){
        AnimationSet set = new AnimationSet(false);
        //旋轉動畫設計

        RotateAnimation rotate = new RotateAnimation(0,360,Animation.RELATIVE_TO_SELF,0.5f,
                Animation.RELATIVE_TO_SELF,0.5f);

        rotate.setDuration(2000);
        rotate.setFillAfter(true);

        //旋轉動畫設置
        ScaleAnimation scale = new ScaleAnimation(0,1,0,1, Animation.RELATIVE_TO_SELF,0.5f,
                Animation.RELATIVE_TO_SELF,0.5f);
        //設置動畫持續時間
        scale.setDuration(2000);
        //是否保持動畫結束時的狀態
        scale.setFillAfter(true);

        //漸變色動畫設計(透明度變化)
        AlphaAnimation alpha = new AlphaAnimation(0,1);

        alpha.setDuration(3000);
        alpha.setFillAfter(true);

        set.addAnimation(rotate);
        set.addAnimation(scale);
        set.addAnimation(alpha);
        //爲佈局增加動畫效果
        rlRoot.startAnimation(set);

    }


}
爲了全屏顯示,我們需要在Mainifest文件裏把這個Activity的主題設置一下,設置爲全屏幕無標題欄的樣式
<activity android:name=".startFlashActivity" android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
這樣就完成了一個簡單的啓動頁面製作,效果如圖




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章