[Android] Android development optimization-UI optimization (2)

Source: Internet
Author: User

In an application, there are usually multiple activities, each of which corresponds to a UI layout file. In general, in order to maintain a uniform style between different windows, many identical la s will be used in these UI layout files. If we rewrite the same layout in every XML file, one is code redundancy and poor readability, and the other is difficult to modify, which is very unfavorable for later modification and maintenance. Therefore, in general, we need to write code with the same layout into a single module. Then, we can reuse the layout code through the <include/> label when using it.

Normally, some applications have a title bar at the top. Similar.

Example of the graph title bar

 

If most of the activity la s in the project contain such a title bar, you can separate the la s of the title bar into an XML file.

<Relativelayout

Android: layout_width = "fill_parent"

Android: layout_height = "wrap_content"

Android: gravity = "center"

Android: Background = "@ drawable/navigator_bar_bg"

Xmlns: Android = "http://schemas.android.com/apk/res/android">

<Textview

Android: Id = "@ Android: ID/Title"

Android: layout_width = "fill_parent"

Android: layout_height = "wrap_content"

Android: layout_centervertical = "true"

Android: gravity = "center"

Android: hint = "title"

Android: textappearance = "? Android: ATTR/textappearancemedium "/>

<Imageview

Android: Id = "@ Android: ID/closebutton"

Android: layout_width = "wrap_content"

Android: layout_height = "wrap_content"

Android: layout_alignparentright = "true"

Android: src = "@ drawable/Close"/>

</Relativelayout>

 

We name the above XML file "navigator_bar.xml". Other XML layout files of the activity that require the title bar can be directly referenced.

<Include layout = "@ layout/navigator_bar"/>

 

Experience Sharing:

Generally, the overall UI style can be roughly determined at the initial stage of the project. Therefore, you can make some planning in the early stages and write out the common modules first.

Below is a shared layout that may be extracted:

1) background. Some applications use a unified background on different interfaces. The Default background may be modified frequently in the future, so the background can be made into a common module.

2) title bar of the header. If the application has a uniform header title bar, it can be extracted.

3) navigation bar at the bottom. If the application has a navigation bar and most activities have the same navigation bar at the bottom, you can write the navigation bar as a common module.

4) listview. Most applications use listview to display multiple data entries. The style of listview may be adjusted frequently in the later stage of the project, so it is better to use listview as a common module.

 

Blog related to optimization series:

Android development optimization-memory optimization for bitmap

Android development optimization-using soft references and weak references

Android development optimization-code optimization

Android development optimization-UI optimization (1)

Android development optimization-UI optimization (2)

Android development optimization-UI optimization (3)

 

---------------------------------------------------------------------------

Http://blog.csdn.net/arui319

An excellent solution for Android Application Development has been published. This article is part of the first draft. Welcome to purchase and read.

This article can be reproduced, but please keep the above author information.

Thank you.

---------------------------------------------------------------------------

 

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.