Teach you to develop Android

Source: Internet
Author: User

In fact, this directory structure for the first time to see or quite let people flustered panic.

AndroidNow we have introduced a build system called Gradle, which you can understand as a C + + Makefile or node inside gulp .

Android StudioThe inside is a sub-module for development, aappYou can have only one module, or you can have multiple modules (such as some libraries you have developed yourself). If our application is simple enough, then there is only one module,Android StudioThe module created by default is calledapp, you can see that there is a small phone icon next to the folder, which represents aAndroid Applicationmodule, rather than aAndroid Libraryor a different module.

To see where our code should be, let's focus on this folder.

srcYes, that is the source source of the directory, we are mainly in this folder to write things.

Where's main?

Let's see, where is the Main function we want?

First we look at src/main the file under the directory AndroidManifest.xml .

androidmanifest   is a most important document describing the app, some definition of content, theme settings are here, if familiar with  < Code style= "PADDING:2PX 4px; Font-family:monaco,menlo,consolas, ' Courier New ', monospace; Border:none; Background-color:rgb (247,247,249) ">node   's friends must know  package.json  

We see, in androidmanifest, the presence of  main    launcher   words, activity   with both of them described, it became the first  activity .

In the src/main/java folder, find MainActivity , open, see one onCreate of the functions

As the name implies, this function is in thisActivityCalled at the time of creation, it first invokes the OnCreate method of the next parent class (not omitted) and then calls thesetContentViewMethod, this method is to tell the Android system: which layout file do I use to render thisActivity, okay, here's an entrance.ActivityIt's all created.

Note: inAndroidSystem,ActivityThe object of the class is not intended for developers to go directly tonew, the life cycle of itdirect control by the systemBecause we don't take control.ActivityLife cycle, so when it's time to call back what functions become extraordinarily important. The best place to learn programming is official documentation, and if you want to learn more about the Android activity life cycle of children's shoes, I recommend here to see the official description of it Portal: Http://developer.android.com/training/basics /activity-lifecycle/index ....

How is the interface customized?

Next talk about  android   in the layout system, known,  android   was initially designed for relative layout. It provides a lot of powerful layout features, we first learn the next  android   The two most common layouts:

    1. Linear layout (LinearLayout)
    2. Relative layout (relativelayout)

Linear layout is where the child controls are arranged sequentially, and the linear layout can be set in the direction, from top to bottom (vertical) or from left to right (horizontal). The relative layout is freer, and if you add a child control without setting any properties, the position of the subspace is at the upper-left corner of the container (0,0). If you want to change the position, you can determine the position of the control by its position in the container (top left, right, bottom left, bottom right, middle, left, center vertically, right alignment, etc.), or the alignment of the sibling node.

Layout-related references can be seen in this link: http://developer.android.com/training/basics/firstapp/building-ui.html

How to interact with controls

InActivityMedium, andxmlThe associated bindings are in thesetContentViewThis step is done.ActivityAfter that, a callback calledonContentChangedmethod, in this method, you can use code similar to the following:

TextView textView = findViewById(R.id.textview);

r.id.textview   is you in  xml   specified in android:id  , usually, in a  xml   file, same  id   only allowed to occur once.

Get a reference to the control, we can call some of the control's methods to get the content we want, or set the content we want, for example, I quote here TextView , you can be as follows:

textView.getText()

Get to textView the inside of the content.

The above is the basic UI part of the introductory explanation. Next, we can look at the entire structure of the app to be written.






Http://www.haoqijie.com/u/4256/book
Http://www.haoqijie.com/u/4258/book
Http://www.haoqijie.com/u/4261/book
Http://www.haoqijie.com/u/4262/book
Http://www.haoqijie.com/u/4263/book
Http://www.haoqijie.com/u/4264/book
Http://www.haoqijie.com/u/4265/book
Http://www.haoqijie.com/u/4266/book
Http://www.haoqijie.com/u/4267/book
Http://www.haoqijie.com/u/4268/book
Http://www.haoqijie.com/u/4269/book
Http://www.haoqijie.com/u/4270/book
Http://www.haoqijie.com/u/4271/book


Http://www.haoqijie.com/u/4272/book
Http://www.haoqijie.com/u/4273/book
Http://www.haoqijie.com/u/4274/book


Http://www.haoqijie.com/u/4275/book
Http://www.haoqijie.com/u/4276/book
Http://www.haoqijie.com/u/4277/book


Http://www.haoqijie.com/u/4278/book
Http://www.haoqijie.com/u/4279/book
Http://www.haoqijie.com/u/4280/book
Http://www.haoqijie.com/u/4281/book
Http://www.haoqijie.com/u/4282/book
Http://www.haoqijie.com/u/4283/book
Http://www.haoqijie.com/u/4284/book
Http://www.haoqijie.com/u/4285/book
Http://www.haoqijie.com/u/4286/book
Http://www.haoqijie.com/u/4287/book




Http://www.haoqijie.com/u/4288/book
Http://www.haoqijie.com/u/4289/book
Http://www.haoqijie.com/u/4290/book




Http://www.haoqijie.com/u/4291/book
Http://www.haoqijie.com/u/4291/book


Http://www.haoqijie.com/u/4292/book
Http://www.haoqijie.com/u/4293/book
Http://www.haoqijie.com/u/4293/book
Http://www.haoqijie.com/u/4294/book
Http://www.haoqijie.com/u/4295/book
Http://www.haoqijie.com/u/4295/book
Http://www.haoqijie.com/u/4296/book
Http://www.haoqijie.com/u/4297/book
Http://www.haoqijie.com/u/4298/book
Http://www.haoqijie.com/u/4299/book

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Teach you to develop Android

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.