Android(安卓)设置应用启动动画
16lz
2021-01-26
流程如下:
- 导入一张图片到Android项目中去
- 新建一个welcomeActivity
- 修改ActivityManifest文件
1.导入一张图片到Android项目
找到一张图片,粘贴复制到项目下drawable目录下(注意图片的名字,只能是小写字母、数字和下划线组成)
2.新建welcomeActivity
2.1 修改布局文件activity_welcome.xml(添加一个ImageView)
<?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=".WelcomeActivity"> <ImageView android:id="@+id/imageView" android:layout_width="0dp" android:layout_height="0dp" android:scaleType="centerCrop" android:scaleX="1.2" android:scaleY="1.2" android:src="@drawable/welcome_image" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /></androidx.constraintlayout.widget.ConstraintLayout>
2.1 修改activity文件WelcomeActivity
package com.example.gcaimport android.content.Intentimport androidx.appcompat.app.AppCompatActivityimport android.os.Bundleimport android.view.Viewimport androidx.core.view.ViewCompatimport androidx.core.view.ViewPropertyAnimatorListenerimport kotlinx.android.synthetic.main.activity_welcome.*class WelcomeActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_welcome)//设置图片动画 ViewCompat.animate(imageView).apply { //缩放,变成1.0倍 scaleX(1.0f) scaleY(1.0f) //动画时常1秒 duration = 1000 //动画监听 setListener(object : ViewPropertyAnimatorListener { override fun onAnimationEnd(view: View?) { //动画结束 //进入主界面,并结束掉该页面 startActivity(Intent(this@WelcomeActivity, MainActivity::class.java)) finish() } override fun onAnimationCancel(view: View?) { } override fun onAnimationStart(view: View?) { } }) } }}
3.修改ActivityManifest文件
这里要做的就是新建一个style(全屏)给WelcomeActivity,同时让WelcomeActivity成为启动界面
3.1新建style
在res/values/styles.xml文件内新建一个style(添加以下代码)
<style name="AppTheme.FullScreen"> //style名字 <item name="windowNoTitle">true</item> //不显示标题 <item name="android:windowFullscreen">true</item> //全屏</style>
完成如下:(添加之后的样子)
<resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style> <style name="AppTheme.FullScreen"> <item name="windowNoTitle">true</item> <item name="android:windowFullscreen">true</item> </style></resources>
3.1修改ActivityManifest文件
style(全屏)给WelcomeActivity,同时让WelcomeActivity成为启动界面,修改前:
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:dist="http://schemas.android.com/apk/distribution" package="com.example.gca"> <dist:module dist:instant="true" /> <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"></activity> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application></manifest>
修改后:
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:dist="http://schemas.android.com/apk/distribution" package="com.example.gca"> <dist:module dist:instant="true" /> <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=".MainActivity"></activity> <activity android:name=".WelcomeActivity" android:theme="@style/AppTheme.FullScreen"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application></manifest>
如果觉得有用,点个赞吧
更多相关文章
- 自定义datePicker的实现
- [置顶] Android之 AndroidManifest.xml 文件解析
- 混淆编译
- Java乔晓松-android中调用系统拍照功能并显示拍照的图片
- android中获取电池当前电量
- Android(安卓)N及以上版本应用安装包下载完成自动弹出安装界面的
- Android(安卓)studio DDMS无法导入导出文件的问题
- [Android(安卓)界面] setContentView和inflate区别
- 解决android客户端上传图片到服务端时,图片损坏的问题