Android optimized--ui optimization (iv)

Source: Internet
Author: User

Use a style to replace the background to prevent the activity black background from flashing 1. Original layout
<linearlayout xmlns:android="Http://schemas.android.com/apk/res/android"Android:layout_width="Match_parent"android:layout_height="Match_parent"Android:background="@drawable/img_bg"android:orientation="Horizontal"> <button android:layout_weight="1"Android:layout_width="0"android:layout_height="Wrap_content"android:text="New button"Android:id="@+id/button2"/> <button android:layout_weight="1"Android:layout_width="0"android:layout_height="Wrap_content"android:text="New Button1"Android:id="@+id/button3"/></linearlayout>

Here we use android:background="@drawable/img_bg" to set the background image, but when we start the activity is sometimes a black background, and then we set the background, to the user feel that our program is running slowly

2. Workaround
<resources>    <!-- Base application theme. -->    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">        <!-- Customize your theme here. -->        <item name="android:background">@drawable/img_bg</item>    </style></resources>

We can set a background for the theme so that it doesn't give the user the impression that our app is jammed

3. Know the reason why

1. Because the subject of the program is loaded when the program starts
The background set in 2.Layout is not loaded until the activity is started
So it will let the user see a black background flashed the process.

Android optimized--ui optimization (iv)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.