Day 2, androidday

Source: Internet
Author: User

Day 2, androidday

Pig's Android getting started Day 2

Android interface development experience




This section introduces:

In the previous section, we have a preliminary understanding of the android system features and platform architecture;

I learned how to build an Android development environment using Eclipse or Android studio. I am familiar with the development process of the corresponding IDE;

And the corresponding project directory; understand some related terms, such as aapt and dx; some adb commands commonly used in command line;

APP packaging, compilation, and running processes! In this section, we will first experience the development of the android interface!

Learn the six layout methods, get a preliminary understanding of the four android components, and the App lifecycle, and build a phone dial!

Not much nonsense!



Body:


This section describes the road map:




Learning route analysis:

① Understand what the four android components and Intent are and what they are used! Detailed analysis in subsequent chapters

② Understand the app lifecycle: five states

③ Dig into the HelloWorld project directory

④ Familiar with the six layout Methods

⑤ Familiar with three tips: Status Bar, dialog box and Toast

⑥ Complete implementation of telephone Dialers

7. 9 patch (9 sisters): Make scalable images!




Analysis of Four android components and Intent:





Lifecycle of an application (App:

Note:

Unlike other smartphone operating systems:The life cycle (survival time) of an app is not controlled by the process itself;

InsteadDetermined by the android systemThe main factor is:Importance of processes to usersAnd the currentRemaining in the system

Available memory space;When the available memory is insufficient, the system will terminate some processes to recycle memory resources!


Process level diagram:




A deep understanding of the project directory of the App: 1. resource reference:



2. parsing detailed code under the project directory:

Three important files: Portal



User Interface Development Experience:

Before creating our interface, we need to know something:

1.View class: AllParent class of the visual control, ProvideComponent profilingAndTime Processing Method

2.ViewGroup class: You can have sub-controls, which can be viewedContainer

3. Generally, visible android apps are composed of visual controls and la S! The properties of the control can be found in

Static settings in xml or dynamic settings in Java code


Now, we are about to create the layout of Our Phone Dialer:

There are two methods:① Drag components ② write your own code

I prefer the latter because the code generated by the drag operation has some redundancy.



The Code is as follows:

Main. xml:

<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/LinearLayout1"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    tools:context=".MyActivity"    >    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/input_num" />    <EditText        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:id="@+id/editnum"/>    <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/btn_call"        android:id="@+id/btncall"/></LinearLayout>




Code parsing:

A LinearLayout (linear Layout mode) is defined and the Arrangement direction is set to vertical, that is, a component is placed in one row;

Next we define TextView (text label), EditText (input box), and Button in sequence, which is very simple.



Six la s of Android


LinearLayout: Linear Layout

Link: android --- LinearLayout (linear layout)


RelativeLayout: relative Layout

Link: android --- RelativeLayout (relative layout)


FrameLayout: frame Layout

Link: android --- FrameLayout (frame layout)


TableLayout: table layout

Link: android --- TableLayout (table layout)


AbsoluteLayout: absolute Layout

Link: android --- AbsoluteLayout (absolute layout)


GridLayout: grid layout

Link: android --- GridLayout (grid layout)

 


Layout usage summary:

The common usage is: UseWeight attribute of LinearLayout+RelativeLayout (relative layout)Because this can

Screen ResolutionAdaptive Problem

The so-called self-adaptation problem is: for example, your interface is centered on a mobile phone, but the components are messy after a mobile phone is changed, or the components are stretched.

Deformation, etc! Of course, other la s also need to be learned !!!




Three Tips: dialog box: AlertDialog:

Link: AlertDialog)


Toast (Toast) and Notification (status bar)

Link: Toast and Notification


Complete implementation of the telephone dial:

Based on the previous main. xml layout, add some code in MainActivity:


Package example.jay.com. myfirstapplication; import android. app. activity; import android. content. intent; import android.net. uri; import android. OS. bundle; import android. view. view; import android. widget. button; import android. widget. editText; public class MyActivity extends Activity {private EditText editnum; private Button btncall; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_my); // ① component instantiation editnum = (EditText) findViewById (R. id. editnum); btncall = (Button) findViewById (R. id. btncall); // set the click event for the call button: btncall. setOnClickListener (new View. onClickListener () {@ Override public void onClick (View v) {// obtain the number value in the edit box: String mobile = editnum. getText (). toString (); Intent it = new Intent (); // Add an action for the Intent: Call and write the phone number into it. setAction ("android. intent. action. CALL "); it. setData (Uri. parse ("tel:" + mobile); // start another Activity startActivity (it );}});}}


Code parsing: here we have set a click event for the button. When we click the button, we can get the phone number in the input box and use the Intent to tell the system who I want to Call and who to Call, then write the phone number into Intent, start Intent, and complete


Run:

We need to start another virtual machine:


The VM 5556 has a dial in!




9 MEI: Use of 9patch tool:

Make a scalable dedicated image, .9.png image:

Link: Make some stretched image materials





Android 2-day Quick Start

A video from instructor mars. Pan.baidu.com/.w.89to listen to the top 5 and 6 videos in the first section, you can simply append the video. Each course takes about 30 minutes.

What are the best Android entry books? (42)

Crazy Android handout (version 2) is explained in version 4.2

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.