Android Basic Learning "historical process re-walk"----Android Primer Basics (i)

Source: Internet
Author: User

First, historical Review

With the rapid development of science and technology, has now entered the 4G era, 5G era is about to open. The Android version is fast and is now in its 6.0 version. Occasionally can be seen, mobile phones endanger the current crowd of life, such as staying up late to see the phone will be deeply hurt the eyes, working family on the way down the party, party dinner outside only the mobile phone party. There are some situations, but there is no emphasis on the current social mobile phone in human life, occupy a more and more important position. Mobile phone communication, to mobile phone entertainment, office, so that the mobile phone management of their own wealth. Even in the future, mobile phones will manage our cars and houses. The trend of technology is unstoppable, it is best to be a wave-goers, the second can "drift". Chat a lot of digression, is to say, do mobile development of small partners, you too have eyes!

Take the android again, it's all just beginning ~_~


Second, Android architecture, virtual machine


Kernel as the kernel, drive the hardware, drive the hardware to achieve the ultimate goal effect; to the kernel drive operation, the encapsulation becomes the library file, forms the Library;application is an application, the system application has the telephone, sends the text message, the photograph and so on, the actual development application has the tool, the mall, the game class and so on The application framework consists of top management for Android apps. Includes activity Manager,window Manager, and so on.

Compared to the Jvm,dalvik virtual machine has more advantages, the combination of all the head, pull out of the constant pool, the method is categorized, to achieve all the Java collation. Understanding Help: Compress a file into a compressed package and copy it to increase data transfer speed.


The art virtual machine is then launched. Java, as a high-level language, needs to be compiled before the machine executes commands. Turn on the art virtual machine and translate the program directly into machine language when the program is installed. This allows for direct execution of code commands, thereby increasing efficiency. But the memory is large, the running energy is much, the interior is still unstable, which hinders the rapid expansion of art.


Third, the Android development environment

ADT is the environment with the highest usage rates. Recently, with the gradual maturation of Android studio, the use of ADT is gradually being replaced. Google does not provide follow-up maintenance, is the biggest reason. The following is the project directory structure under the Eclipse environment:


Using Project mode under as, the project directory structure is similar. The greater advantage of as is the internal nesting of gradle, which enables automated packaging, multiple versions, and multi-channel packaging.

ADB is the Android Debug Bridge, which is used to connect the development environment and the operating environment. The ADB command is easy to use. Commonly used ADB commands:

<span Style= "FONT-SIZE:18PX;" >ADB kill-server: Kill service, disconnect adb start-server: Turn on service, connect device "ADB ins Tall xxx.apk: Install mobile Software Installation is not available "ADB Devices: Restart service, link device adb connect 127.0.0.1:6555 link every day simulator adb connect 127.0.0.1:62001 chain Night God simulator adb Uninstall package name: Uninstall mobile software uninstall available adb shell into device adb shell input keyevent back button adb shell input tap X Y Click Coordinate point adb shel     l input swipe x y x y slide adb shell dumpsys activity [Activities] view activity [] optional adb PS is look at the process of the ADB top command is to see the occupancy rate                 View phone CPU Usage 7817 0 15% R 596756K 72764K FG U0_a75 com.ds365.order.test//monkey during Operation     8599 0 3% S 586604K 56884K FG U0_a75 com.ds365.order.test//Run 8599 0 0% s 573724K 55252K BG U0_a75 com.ds365.order.test//background run </SPAN> 
in the development environment, some tools, such as Ddms,hierarchyviewer, are also available.

DDMS can manage virtual machines.

Hierarchyviewer can be used to find the view ID and clarify the relationship between the view. The current tool is very helpful for monkeyrunner automated testing.


四、一个 Small Program

<span style= "FONT-SIZE:18PX;" ><span style= "FONT-SIZE:18PX;"    >public class Mainactivity extends Appcompatactivity {private Button phoneCall;        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_main);        PhoneCall = (Button) Findviewbyid (R.id.phone_call);                Phonecall.setonclicklistener (New View.onclicklistener () {@Override public void OnClick (View v) { /** * Test Send Message */Smsmanager Smsmanager = Smsmanager.getdefault (                );                Smsmanager.sendtextmessage ("15510728213", "Moniqi", "Hello", null, NULL);                /** * Specify intent: Create new object, set action, carry data, trigger action */Intent Intent = new Intent ();                Intent.setaction (Intent.action_call);                Intent.setdata (Uri.parse ("tel://15510728213"));        StartActivity (Intent);    }        }); }/** * Jump to the next interface * * @param view */public void changenextpage (view view) {startactivity (new I    Ntent (Mainactivity.this,onclickeventactivity.class)); }}</span></span>
BASIC Programming Flow: Modify the authoring XML file, write the main class: Find the Care control, add events to the control.
Four ways to click events:

<span style= "FONT-SIZE:18PX;"    >public class Onclickeventactivity extends Activity implements View.onclicklistener {private Button clicksecond;    Private Button Clickthird;    Private Button Clickfour;        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (r.layout.onclick_event_layout);        Clicksecond = (Button) Findviewbyid (R.id.onclick_second);        Clickthird = (Button) Findviewbyid (R.id.onclick_third);        Clickfour = (Button) Findviewbyid (R.id.onclick_four);        Clicksecond.setonclicklistener (New Clicksecond ());            Clickthird.setonclicklistener (New View.onclicklistener () {/** * Third method: Anonymous inner class implementation of the click Method */ @Override public void OnClick (View v) {toast.maketext (onclickeventactivity.this, "anonymous            Partial implementation ", Toast.length_short). Show ();        }        });    Clickfour.setonclicklistener (this); }/** * First way: The Write method in XML * * @param view */public void Clickeventfirst (view view) {Toast.maketext (onclickeventacti    Vity.this, "Write method in XML", Toast.length_short). Show ();            }/** * Fourth method: class implements the OnClick interface */@Override public void onclick (View v) {switch (V.getid ()) { Case R.id.onclick_four:toast.maketext (Onclickeventactivity.this, "class implements the OnClick interface", Toast.length_short). s                how ();        Break        }}/** * Second method: Inner class Implementation click Method */Class Clicksecond implements View.onclicklistener {@Override        public void OnClick (View v) {toast.maketext (Onclickeventactivity.this, "inner class implementation", Toast.length_short). Show (); }}}</span>

Five or four large layouts

The four layouts are: Relativelayout, LinearLayout, Framelayout, Tablelayout. Absolute layout is not recommended for use.

Relative layout (relativelayout):

<span style= "FONT-SIZE:18PX;" ><?xml version= "1.0" encoding= "Utf-8"? ><relativelayout xmlns:android= "http://schemas.android.com/apk/ Res/android "android:layout_width=" match_parent "android:layout_height=" match_parent "> <Button Andro Id:id= "@+id/middle" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android: Layout_centerinparent= "true" android:text= "middle"/> <button android:id= "@+id/left" Android:lay Out_width= "Wrap_content" android:layout_height= "Wrap_content" android:layout_centervertical= "true" an droid:layout_toleftof= "@+id/middle" android:text= "left"/> <button android:id= "@+id/right" Android        Oid:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:layout_centervertical= "true"        android:layout_torightof= "@+id/middle" android:text= "right"/> <button android:id= "@+id/up"Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:layout_above= "@+id/middle"        Android:layout_centerhorizontal= "true" android:text= "on"/> <button android:id= "@+id/down" Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:layout_below= "@+id/mid Dle "android:layout_centerhorizontal=" true "android:text=" under "/> <button android:layout_width = "Wrap_content" android:layout_height= "wrap_content" android:text= "upper left"/> <button Android:la        Yout_width= "Wrap_content" android:layout_height= "Wrap_content" android:layout_alignparentright= "true" android:text= "top Right"/> <button android:layout_width= "wrap_content" android:layout_height= "Wrap_conte NT "android:layout_alignparentbottom=" true "android:text=" left Down "/> <button Android:layout_widt        H= "Wrap_content"android:layout_height= "Wrap_content" android:layout_alignparentbottom= "true" android:layout_alignparentright = "true" android:text= "bottom Right"/></relativelayout></span>


Linear layout (LinearLayout):

<span style= "FONT-SIZE:18PX;" ><?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/ Res/android "android:layout_width=" match_parent "android:layout_height=" match_parent "android:orientation=" vertic        Al "> <linearlayout android:layout_width=" match_parent "android:layout_height=" Wrap_content " android:orientation= "Horizontal" > <textview android:layout_width= "wrap_content" Android        : layout_height= "wrap_content" android:layout_margin= "4DP" android:text= "LinearLayout first Row first column"/>            <textview android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android:layout_margin= "4DP" android:text= "LinearLayout first row second column"/> </LinearLayout> <linearlay Out android:layout_width= "match_parent" android:layout_height= "wrap_content" android:orientation= "hor IzoNtal "> <textview android:layout_width=" 0dp "android:layout_height=" Wrap_content "        Android:layout_margin= "4DP" android:layout_weight= "1" android:text= "linearlayout second row first column"/> <textview android:layout_width= "0DP" android:layout_height= "Wrap_content" Androi D:layout_margin= "4DP" android:layout_weight= "1" android:text= "linearlayout second row second column"/> </line Arlayout></linearlayout></span>

frame Layout (framelayout):

<span style= "FONT-SIZE:18PX;" ><?xml version= "1.0" encoding= "Utf-8"? ><framelayout xmlns:android= "Http://schemas.android.com/apk/res /android "android:layout_width=" match_parent "android:layout_height=" match_parent "> <TextView androi D:layout_width= "350DP" android:layout_height= "350DP" android:background= "@color/black" android:layout _gravity= "center"/> <textview android:layout_width= "300DP" android:layout_height= "300DP" and roid:background= "@color/blue" android:layout_gravity= "center"/> <textview android:layout_width= "260 DP "android:layout_height=" 260DP "android:background=" @color/red "android:layout_gravity=" center "/&gt    ; <textview android:layout_width= "200DP" android:layout_height= "200DP" android:background= "@color/gr Een "android:layout_gravity=" center "/> <textview android:layout_width=" 100DP "Android:layout_height= "100DP" android:background= "@color/coloraccent" android:layout_gravity= "center"/></framela Yout></span>

Relativelayout Property Description:

First Class: Property value is True or False

Android:layout_centerhrizontal Horizontal Center
Android:layout_centervertical Vertical Center
Android:layout_centerinparent is completely centered relative to the parent element
Android:layout_alignparentbottom snaps to the bottom edge of the parent element
Android:layout_alignparentleft snaps to the left edge of the parent element
Android:layout_alignparentright snaps to the right edge of the parent element
Android:layout_alignparenttop snaps to the top edge of the parent element
android:layout_alignwithparentifmissing if the corresponding sibling element cannot be found, then the parent element is the reference.

Second class: The attribute value must be the reference name of the id "@id/id-name"
Android:layout_below at the bottom of an element
Android:layout_above at the top of an element
Android:layout_toleftof on the left side of an element
Android:layout_torightof on the right side of an element

Android:layout_aligntop aligns the top edge of this element with the top edge of an element
Android:layout_alignleft aligns the left edge of this element with the left edge of an element
Android:layout_alignbottom aligns the bottom edge of this element with the bottom edge of an element
Android:layout_alignright aligns the right edge of this element with the right edge of an element

Class III: Attribute values are specific pixel values, such as 30dip,40px
Android:layout_marginbottom distance from the bottom edge of an element
Android:layout_marginleft distance from the left edge of an element
Android:layout_marginright distance from the right edge of an element
Android:layout_margintop distance from the top edge of an element

Android:gravity
The Android:gravity property is the qualification for the view content.  For example, a button above the text. You can set the text on the left side of the view, on the right, and so on. Take the button as an example, android:gravity= "right" then the text on the button


Android:layout_gravity
Android:layout_gravity is used to set the position of the view relative to the parent view. For example, a button in the LinearLayout, you want to put the button on the left, right and other positions can be set by this property. Take button For example, android:layout_gravity= "right" button on


EditText's Android:hint
Sets the prompt information in the input box when EditText is empty.


ImageView's Android:scaletype:
Android:scaletype is a size that controls how the picture resized/moved to the ImageView. The meaning difference of Imageview.scaletype/android:scaletype value:


Center/center is centered on the original size of the image, and when the picture is longer/wider than the length/width of the view, the center portion of the image is displayed
Center_crop/centercrop proportionally enlarges the size of the image so that the image is long (wide) equal to or greater than the length (width) of the view
Center_inside/centerinside Displays the contents of the picture in full, by scaling it down or the original size to make the picture long/wide equal to or less than the length/width of the view
Fit_center/fitcenter enlarge/Shrink the picture to the width of the view, centered on the display
Fit_end/fitend Zoom in/out to the width of the view, displayed in the lower part of the view
Fit_start/fitstart enlarge/Shrink the image to the width of the view, displayed in the upper part of the view
Fit_xy/fitxy The picture is not scaled up/down to the view size display
The Matrix/matrix is drawn with a matrix and is displayed by zooming in and out of the image.

SOURCE download

Impregnable pass apocalypse is like Iron now ~_~

Android Basic Learning "historical process re-walk"----Android Primer Basics (i)

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.