1.jpg

全部步驟開始前,先建立一個空的activity,並在Layout中塞一個 TextView,寫著我是主程式,如下:

1.jpg

Layout:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
   
xmlns:app="http://schemas.android.com/apk/res-auto"
    
xmlns:tools="http://schemas.android.com/tools"
   
android:layout_width="match_parent"
   
android:layout_height="match_parent"
   
tools:context=".MainActivity">
    <
TextView
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:text="我是主程式"
       
app:layout_constraintBottom_toBottomOf="parent"
       
app:layout_constraintLeft_toLeftOf="parent"
       
app:layout_constraintRight_toRightOf="parent"
       
app:layout_constraintTop_toTopOf="parent" />
</
androidx.constraintlayout.widget.ConstraintLayout>

 

Step 1: 建立開頭動畫用的 XML (漸進)

2.jpg

 

Animation code:

<?xml version="1.0" encoding="utf-8"?>

  <set xmlns:android="http://schemas.android.com/apk/res/android">

    <alpha

        android:fromAlpha="1.0"

        android:toAlpha="0.0"

        android:duration="5000">

  

    </alpha>

</set>

 

Step 2: 先選一張自己想要的開頭動畫圖片,並且放到 res/drawable資料夾中

3.jpg

 

Step 3: 建立一個開頭的Layout

4.jpg

 

Layout:

<?xml version="1.0" encoding="utf-8"?>

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:orientation="vertical" android:layout_width="match_parent"

    android:layout_height="match_parent">

    <ImageView

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        android:id="@+id/imageView"

        android:src="@drawable/dragonball"

        android:scaleType="fitCenter"/>

</LinearLayout>

 

Step 4: 撰寫開頭動畫程式碼

5.jpg

WelcomeActivity:

 

 

 

Step 5: 改動開啟APP的設定檔 AndroidManifest.xml

6.jpg

 

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>

  <manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="tw.idv.ken.appstartanim">

  

    <application

        android:allowBackup="true"

        android:icon="@mipmap/ic_launcher"

        android:label="@string/app_name"

        android:roundIcon="@mipmap/ic_launcher_round"

        android:supportsRtl="true"

        android:theme="@style/AppTheme">

        <activity android:name=".WelcomeActivity">

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />

  

                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

        <activity android:name=".MainActivity"></activity>

    </application>

  

</manifest>

改動的地方為<Activity></Activity>,畢竟要跟Android OS說一開始該讀哪一個Activity,然後原本的Activity也要註冊留著。

 

接著可以在手機上demo看看,畫面如下:

一點進APP

Screenshot_20201029-200020[1].png

 

之後跳轉

Screenshot_20201029-200026[1].png

 

打完收工。

 

Reference:

http://melvin0530.blogspot.com/2016/07/android-app.html

arrow
arrow

    葛瑞斯肯 發表在 痞客邦 留言(0) 人氣()