Front-end Android Primer (2) – Introduction to the program catalog and UI

Source: Internet
Author: User

One, the directory structure of the Android program

Open the HelloWorld project we created last time, we will see a directory structure, this is the Android program directory, the approximate role of these directories are as follows:

    • SRC: Source code organization and Management directory.
    • Gen: The automatically generated directory generates some important files, such as R.java, which are not normally required for us to write.
    • Assets: This directory file will not be compiled into binary encoding, used for playback of audio and video, text and other raw format files.
    • Bin: Used to store compiled Java files and apk files.
    • Libs: Store the Android source package or the source package that needs to be introduced.
    • Res: the directory where the program resources are located, including images, values and other types of resources.
    • Androidmanifest.xml: Program configuration file, which describes the program information to the system.

Here we first introduce the directory we used to:

1) src Directory

Open the project's SRC directory, will immediately understand that the original Com.tencent.helloworld "." is equivalent to the path delimiter, Java is this way to manage the storage of different files, that is, the Java package mechanism, now only need to know this concept.

2) Res directory

This directory is used to store the various resources of the Android program and is important for managing resources and the adaptation of the Android UI, which will be used incrementally in later examples. The following directories are mainly included:

Drawable-xxx

An XML file that holds a drawing resource such as a bitmap (Bitmap files) (. png,.9.png,.jpg,.gif) or a status list (state lists), animation (Animation drawables), Graphics (shapes), and so on. Equivalent to a picture resource in a Web page. Where-xxx is used to fit a screen with different pixel densities. It's not going to start here.

Layout

The directory's XML file is used to describe an interface structure for an Android UI interface (Activity) or a System Desktop component (Appwidget). Corresponds to the HTML structure of the Web page.

Menu

The Main.xml file in this directory is used to define the pop-up menu structure at the bottom of Android.

Values-xxx

For storing XML files that define various: character values, color values, values, styles, etc. For example, Dimens.xml is used to define each dimension value, Strings.xml is used to define the text, Colors.xml is used to define each color value, the most important of which styles.xml is used to define the visual style of the view element (CSS equivalent to the Web page). The-XXX function is also used for Android adaptation, which is also not started here.

Androidmanifest.xml file

Each Android application has a androidmanifest.xml file in the root directory that is used to provide the system with the information it needs to provide before the program runs. This file mainly contains the following information:

    • Names the Java package name for the app, which is the unique identity of the app.
    • Describe the composition of the application, including Activity,services.
    • Declares the permissions that the app must have to access the protected part of the API.
    • Declares the environment configuration information that is required when the app runs.
    • Declare the minimum version level of the system Android API that your app requires.
    • Lists the libraries that the app needs to link to.
Second, the Android UI introduction

From the HTML point of view, a web interface, usually composed of DIV elements to complete the structure layout, Img,input,button and other elements to complete the interface construction. The same is true of Android's interface construction, where all UI elements are inherited by the view class in the Android UI world, and then derive the elements for layout such as: Framelayout,linearlayout,relativelayout, Tablelayout, etc., for the interface rendering of component elements such as: Textview,edittext,imageview,videoview and so on. Only the view element and its child elements have a strict inheritance system, which is different from HTML. Shows the view element architecture in Android:

As with CSS, which controls the visual rendering of HTML, Android also controls the visual rendering of view elements through various attributes, and we first look at the familiar HTML and CSS relationships:

Smart Small partners will be asked, CSS properties only a peer relationship, why is it separated? Yes, it simply simulates the hierarchical relationship of "Css" in Android. In Android, each attribute is strictly differentiated and has its own inheritance system.

So here's a very important concept: in Android, the visual rendering of the view class is controlled by a class of two properties. One is the Viwe class itself, such as the background, transparency, inner blank, etc., such as layout properties, such as length, width, margin, position, etc. Show the relationship between them:

Here we need to understand 3 concepts:

The 1,view class's own properties, such as Android, the view class has ID, alpha, padding and other properties, and TextView inherit from the view, so textview in addition to set its own properties TextColor outside, You can also set Id,alpha and so on. So we can set a textview rendering like this:

2, in what layout element, the view within the layout element can use what layout properties. For example, if TextView is inside a linearlayout, you can use the layout properties defined by Linearlayout.layoutparams, such as:

3, layout properties can also be inherited and used, For example, Linearlayout.layoutparams inherits from Viewgroup.marginlayoutparams,viewgroup.marginlayoutparams and inherits from Viewgroup.layoutparams, which can end up as follows Set up:

So, usually in one interface, the layout properties are used as shown:

End: In this article, a brief introduction to the program directory. It is also a general introduction to the concept of the Android UI to clarify the relationship of UI properties, which is especially important for programming behind us, especially for generating views and setting properties with program code. In the next article, we will actually complete the production of an interface and take an example into the knowledge point of the Android UI. Hopefully this article will help small partners on the way to Android learning.

Front-end Android Primer (2) – Introduction to the program catalog and UI

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.