How to efficiently implement the layout of the Android application startup page?

This article mainly explains how to quickly define the startup page layout and the problems encountered

Scene analysis

I have recently encountered a few core problems to be solved when I started the home page at work.

  • The startup page fills the entire screen, how to keep the ratio stretched according to a fixed horizontal and vertical ratio.
  • How to adapt to all new and old model system versions.
  • All UI must be completed in the drawable. Some people may think that it can be placed directly in the layout file, but there is a problem with the delay of the black screen at startup. The main reason is that the application startup takes a certain amount of time. .

The corresponding solution is as follows

  • The whole content is divided into foreground and background. The background is automatically stretched according to the screen ratio. It needs a fixed position and a fixed size to move forward.
  • This will be discussed separately after encountering a pit.
  • Use drawable layer-list to achieve

achieve

The principle of implementation is to configure the windowBackground of the drawable for the activity

Target effect

c3eabc63d9bb58eeb5940fe952d72765

Configure 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>

Define 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>

Application theme

<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>

Adaptation problem

The adaptation problem encountered this time is that some layout attributes do not take effect on version 5.1. This problem was solved later through property configuration.
285af7122aced077117c377ab88678f7

The solution is through the configuration on the right
c2a6ecaf2f10c552ee91e5a27595c4d2

Guess you like

Origin blog.csdn.net/wsx1048/article/details/108688985