Android Memory optimizer 5-Interface UI optimization (2)

Source: Internet
Author: User

In an application, there is typically more than one activity, and each activity corresponds to a UI layout file. In general, in order to keep the style of the different Windows unified, in these UI layout files, almost certainly will use a lot of the same layout. If we rewrite the same layout in every XML file, one is code redundancy, readability is poor, the other is cumbersome to modify, and very detrimental to late modification and maintenance. So, in general, we need to write the same layout code in a separate module, and then use the <include/> tag to reuse the layout code.

Frequently, some apps have a title bar at the top. Similar to the following.

Example of a graph title bar

If the layout of most activities in your project contains such a title bar, you can write the layout of the title bar separately 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 named the XML file above as "Navigator_bar.xml", and other XML layout files that require the activity of the title bar can refer to this file directly.

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

Experience Sharing:

In general, the overall UI style can be broadly defined at the beginning of the project. So in the early days you could do some planning and write out the generic modules first.

The following are common layouts that you might be able to extract:

1) background. Some applications use a unified background in different interfaces. The default background may often be modified later, so the background can be made into a common module.

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

3) Bottom of the navigation bar. If the navigation bar is applied and most of the activity's bottom navigation bar is the same, the navigation bar can be written as a generic module.

4) ListView. Most applications use the ListView to show multiple data. The ListView style may often be adjusted later in the project, so it is better to use the ListView as a common module.

Optimization Series related blog posts:

Android Development Optimization--memory optimization for bitmap

Android Development optimization-using soft references and weak references

Optimized for Android development – from a code perspective

Android Development Optimization-UI optimization (1)

Android Development Optimization-UI optimization (2)

Android Development Optimization-UI optimization (3)

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

http://blog.csdn.net/arui319

The "Android Application development Solution" has been published, this article is part of the first draft. Welcome to buy Reading.

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

Thank you.

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



From for notes (Wiz)

Android Memory optimizer 5-Interface UI optimization (2)

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.