Analysis of Android development optimization: a detailed explanation of Interface UI optimization (2)

Source: Internet
Author: User

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.Copy codeThe Code is as follows: <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.Copy codeThe Code is as follows: <include layout = "@ layout/navigator_bar"/>

Copy codeThe Code is as follows:

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)The title bar of the header. If the application has a uniform header title bar, it can be extracted.

3)The 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.

Related Article

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.