Android UI acceleration skills

Source: Internet
Author: User

When the Activity of your Android app needs to use the Custom drawable background, using the Custom Theme can save the display loading speed of the UI.
 
Before explaining the cause, you need to clarify the concept:
 
Window background. Many people think that this background should be the layout background when setContentView is called. In fact, after you call this method, Android will add your View to the window of the corresponding Activity, this window not only contains your View, but also contains a lot of other things, 1.1
 

 
Fig 1.1
 
The View highlighted in blue is a kind of stuff called DecorView. It is the guy who actually holds the window's background drawable! In the current Activity, call getWindow (). setBackgroundDrawable () to modify the Drawable of DecorView.
 
If you are using the default topic of Android, a default background drawable will be set to your Activity (DecorView's background drawable ). In most cases, this does not affect the performance. However, if you want to set an opaque full screen image as the background image for your Activity, the default background Drawable is redundant, rendering performance may be affected.
 
You can use the custom Theme to set the android: windowBackground attribute to your own Drawable resource. You can replace the default window background drawable. It is simple and solves performance problems.
 
Example (From Shelves)
 
Background Drawable Resource
<Bitmap xmlns: android = "http://schemas.android.com/apk/res/android"
Android: src = "@ drawable/shelf_panel"
Android: tileMode = "repeat"/>
Custom Theme
<Resources>
<Style name = "Theme. Shelves" parent = "android: Theme">
<Item name = "android: windowBackground"> @ drawable/background_shelf </item>
<Item name = "android: windowNoTitle"> true </item>
</Style>
</Resources>

From Xue xianliang's blog

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.