Piglet's Android Getting Started Day 2
Android Interface Development First Experience
Introduction to this section:
In the previous section, we have a preliminary understanding of the Android system features and platform architecture;
Learned to use Eclipse or Android studio to build Android development environment, familiar with the corresponding IDE development process;
and the corresponding engineering catalogue; Some relevant nouns, aapt,dx, etc.; some of the ADB directives commonly used by the command line;
App packaging, compiling, and running processes! In this section we will experience the development of the Android interface!
Learn six layouts, get a basic understanding of Android's four components, and the lifecycle of your app, build a phone dialer, and much more!
Don't say much nonsense!
Body:
Learning Roadmap for this section:
Learning route Analysis:
① understand what the four components and intent of Android are, what to do with them! In the following chapters, we will explain in detail
② Learn about the app life cycle: five states
③ in-depth analysis of HelloWorld's engineering catalogue
④ familiar with six layout methods
⑤ familiar with three ways of prompting: status bar, dialog box and toast
Complete implementation of ⑥ telephone dialer
⑦9patch (9 sister) use: Make Scalable pictures!
Android four major components and intent initial analysis:
the life cycle of the app (app):
Attention:
Unlike other smartphone operating systems :The app's life cycle (survival time) is not controlled by the process itself ;
It is determined by the Android system , and the main factor of the impact: the importance of the process to the user , as well as what remains in the current system
available memory space; When there is not enough memory available, some processes are terminated to reclaim memory resources!
Process level diagram:
Learn more about the app's Engineering catalog:1. References to resources:
2. Detailed code parsing in the engineering catalogue:
Three important documents: Portal
user Interface Development First experience:
Before we create our world, we need to know something first:
1.View class : Is the parent class for all visual controls , providing a description of the component and a time-processing method
2.ViewGroup class : Can have child controls, can be considered as containers
3. Commonly visible Android apps are made up of visual controls + layouts! The properties of the control can be
Statically set in XML or dynamically in Java code
Well, then we're going to start creating the layout of our Phone Dialer:
There are two ways to do this:① Drag components ② write their own code
The author prefers the latter, because the code for drag generation 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:
is to define a linearlayout (linear layout) and set the arrangement direction to vertical, that is, one line to place a component;
Then we define TextView (text label), EditText (input box), button (buttons), very simple
the six major layouts of Android
linearlayout: Linear layout
Link:android---linearlayout (linear layout) detailed
relativelayout: Relative layout
Link:android---relativelayout (relative layout) detailed
framelayout: Frame layout
Link:android---framelayout (frame layout) detailed
tablelayout: Table layout
Link:android---tablelayout (table layout) detailed
absolutelayout: Absolute Layout
Links:android---absolutelayout (absolute layout) detailed
GridLayout: Grid layout
Links:Android---GridLayout (Grid layout) detailed
Summary of layout usage:
The common usage is to use LinearLayout's Weight property +relativelayout (relative layout) for layout, as this can
Solve the adaptive problem of the screen
The so-called adaptive problem is that one of your interfaces is centered on a cell phone, but the components get messed up when you change a phone, or stretch
Deformation and so on! Of course other layouts are also necessary to learn!!!
three ways to prompt:dialog box:
alertdialog:
Link: Parent class for dialog box (alertdialog)
toast(toast) and Notification(status bar)
Links: Toast and notification
complete implementation of the Phone Dialer:
On the basis of the previous Main.xml layout, after adding some code in the 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 Click events for the Dial button: Btncall.setonclicklistener (new View.onclicklistener () {@Override public void OnClick (View v) {//Gets the number value in the edit box: String mobile = Editnum.gettext (). toString (); Intent it = new Intent (); Add a behavior for intent: Make a call and write the phone number to the IT it.setaction ("Android.intent.action.CALL"); It.setdata (Uri.parse ("Tel:" +mobile)); Start another activity startactivity (it); } }); }}
Code parsing:Here we set a click event for the button, and when we click the button, get the phone number in the input boxthrough intent intent, tell the system, who am I going to call,call, and then write the phone number intent, start intent, finish
Run:
We need to start a separate virtual machine:
Virtual Machine 5556 has a phone dialed in!
Nine sister: Use of 9patch tools:
Make scalable, proprietary images,. 9.png Images:
Link: Make a partially stretched picture material