本文主要說明啟動頁布局如何快速定義和遇到的問題
場景分析
最近作業上做首頁啟動頁,遇到了幾個要核心解決的問題,
- 啟動頁充滿整個螢屏的,如何按固定橫縱比例保持比例拉伸,
- 如何去適配所有的新老機型系統版本,
- 所有的UI都要在drawable中完成,有人可能會想到直接可以放在布局檔案當中,但是這樣有一個問題就是在啟動的時候會黑屏的延時,主要原因也是因為應用啟動是需要占用一定的時長,
對應的解決方案是如下
- 整個內容分為前景和背景,背景按螢屏比例自動拉伸,前進需要固定位置固定大小
- 這個遇到了個坑后面單獨講,
- 使用drawable layer-list來實作
實作
實作的原理就是通過給activity配置drawable 的windowBackground
目標效果

配置drawable
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:gravity="fill">
<bitmap
android:gravity="fill"
android:src="@drawable/bg_flash_new" />
</item>
<item android:gravity="fill_horizontal|top">
<bitmap
android:gravity="fill_horizontal|top"
android:src="@drawable/fg_flash_top" />
</item>
<item android:gravity="center_horizontal|bottom"
android:bottom="150dp">
<bitmap
android:gravity="center_horizontal|bottom"
android:src="@drawable/fg_flash_notta" />
</item>
<item android:gravity="center_horizontal|bottom"
android:bottom="54dp">
<bitmap
android:gravity="center_horizontal|bottom"
android:src="@drawable/fg_flash_huawei" />
</item>
</layer-list>
定義style
<style name="Splash" parent="AppTheme">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowBackground">@drawable/splash_huawei</item>
</style>
應用主題
<activity
android:name=".ui.home.FlashActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden"
android:theme="@style/Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
適配問題
本次遇到的適配問題是在5.1版本上面,有些布局屬性不生效的問題,后面通過屬性配置解決了此問題,

解決的方式通過右邊的配置

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/99497.html
標籤:其他
上一篇:各位大佬:想更新一下pip,但總是報錯,請問這是怎么回事
下一篇:python 越界的問題請教
