【Android学习笔记】设置App启动页
生活随笔
收集整理的這篇文章主要介紹了
【Android学习笔记】设置App启动页
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
先將啟動頁放到項目資源中,圖片一般是1080*1920的jpg。
新建一個activity,如圖:
創建成功之后,打開剛剛創建的activity,來進行代碼的編寫:
public class BZLaunchActivity extends AppCompatActivity {private final int SPLASH_DISPLAY_LENGHT = 2000;//兩秒后進入系統,時間可自行調整@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_bzlaunch);//在BZLaunchActivity停留2秒然后進入BZLaunchActivitynew android.os.Handler().postDelayed(new Runnable() {@Overridepublic void run() {Intent mainIntent = new Intent(BZLaunchActivity.this,MainActivity.class);BZLaunchActivity.this.startActivity(mainIntent);BZLaunchActivity.this.finish();}},SPLASH_DISPLAY_LENGHT);} }然后去xml配置文件里畫界面,配置文件在res/layout與創建時layout同名的的xml文件,代碼如下:
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.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=".BZLaunchActivity"><ImageViewandroid:id="@+id/imageView"android:layout_width="wrap_content"android:layout_height="wrap_content"//讓圖片全屏顯示android:scaleType="fitXY"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent"//啟動頁圖片app:srcCompat="@mipmap/zqq_launch" /> </android.support.constraint.ConstraintLayout>如果android:scaleType="fitXY"不設置,可能出現啟動頁圖片不全屏的情況。
最后要去AndroidManifest.xml文件中修改一下啟動頁的activity的位置,未修改之前,MainActivity是在前面的,這個時候運行App,發現并沒有啟動頁,我們需要把啟動頁的activity調到MainActivity的前面,也就是:
好了,完成上面這些,再運行App,就會看到啟動頁了。
總結
以上是生活随笔為你收集整理的【Android学习笔记】设置App启动页的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 为Pdf批量添加水印
- 下一篇: swiper的使用