前言
由于筆者操作不當,將專案搞崩了,所以打算重寫一遍,記下開發程序,作為學習記錄,此軟體能實作最普通的單詞查詢功能,也有啟動影片、登錄注冊之類的功能,但筆者目前能力有限,未能將其完善,這是初學階段的一個半成品,存在不少漏洞,望讀者海涵,
一、前期準備
1.啟動影片
(1)創建一個empty activity,命名為Peach Dictionary,
(2)新建一個activity,作為軟體啟動影片,在manifest中將其設為主界面,
將.welcome設定為主界面
<activity
android:name=".welcome"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
activity_welcome.xml
<?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=".welcome">
<ImageView
android:id="@+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@+id/guideline4"
app:srcCompat="@drawable/img" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.08" />
<ImageView
android:id="@+id/imageView5"
android:layout_width="233dp"
android:layout_height="179dp"
android:background="#00FFFFFF"
android:backgroundTint="#00FFFFFF"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/img_1" />
</androidx.constraintlayout.widget.ConstraintLayout>
在gradle里面添加
apply plugin: 'kotlin-android-extensions'
以運行kotlin代碼
welcome.kt(此段參考,侵刪)
package com.example.peachdictionary
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.core.view.ViewCompat
import androidx.core.view.ViewPropertyAnimatorListener
import kotlinx.android.synthetic.main.activity_welcome.*
class welcome : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_welcome)
//設定圖片影片
ViewCompat.animate(imageView4).apply {
//縮放,變成1.0倍
scaleX(1.0f)
scaleY(1.0f)
//影片時常1秒
duration = 1000
//影片監聽
setListener(object : ViewPropertyAnimatorListener {
override fun onAnimationEnd(view: View?) { //影片結束
//進入主界面,并結束掉該頁面
startActivity(Intent(this@welcome, MainActivity::class.java))
finish()
}
override fun onAnimationCancel(view: View?) {
}
override fun onAnimationStart(view: View?) {
}
})
}
}
}
3.在manifest中將主題修改
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
實作效果:

轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/385645.html
標籤:其他
上一篇:shape繪制形狀基礎詳細決議
