Android App Development Diary

Source: Internet
Author: User

1. Determine the Android program structure

4 main Blocks

Main.xml This is the UI structure of the mobile interface.

R,java system Resource list, equivalent to the hardware of the systems file (specifically how the unknown origin generated)

Androidmanifest.xml system Function list, add function to write code inside (do not know other than the activity and other classes are also to write inside)

Mainactivity.java where you biancheng.

2, Android program flow

The activity class is just a class that contains some basic window functionality, and is actually a blank box after startup.

You need to add your own design, here is a statement of the activity of an empty project

    protected void onCreate (Bundle savedinstancestate) {        super. OnCreate (savedinstancestate);         Setcontentview (R.layout.activity_main);    }
Bundle Savedinstancestate, this is to save its state when the activity is aborted, and to save the content unknown origin
The code is as follows
public void Onsaveinsancestate (Bundle saveinsancestate) {
Super.onsaveinsancestate (saveinsancestate);
}
In practice, when an activity is completed, if it needs to be saved, in Onsaveinsancestate, the state data is placed in the form of Key-value in Saveinsancestate. Thus, when an activity is created, the state data can be obtained from the OnCreate parameter saveinsancestate.
Setcontentview (R.layout.activity_main);
Activity_main is a layout file is how the control is displayed, Setcontentview is to set an activity display interface, this sentence is set this sentence is the activity of the r.layout under the
Activity_main Layout files for layout
Using Setcontentview, you can dynamically switch the view displayed in the activity so that different interfaces can be displayed without multiple activities, so it is no longer necessary to transfer data between activity, and variables can be referenced directly. However, in the Android SDK to our default Hello World program, call is the Setcontentview (int layoutresid) method, if you use this method to switch view, after switching back, can not display the changes before the change of appearance, In other words, the equivalent of re-displaying a view is not to hide the original view and display it again. In fact, Setcontentview is a polymorphic method, we can first use Layoutinflater to introduce the layout XML file into a View object, and then through the setcontentview (view view) method to switch views. Because all the changes to the view are saved in the View object, when you switch back to the original view, you can directly display the original modified look
Setcontentview related uses are as follows:
Http://www.360doc.com/content/12/1106/15/8189294_246188695.shtml
And then here's the next paragraph
 Public Boolean Oncreateoptionsmenu (Menu menu) {        //  inflate the menu; This adds items to the action bar if it I s present.         Getmenuinflater (). Inflate (R.menu.main, menu);         return true ;    }
Oncreateoptionsmenu For specific usage See link http://www.linuxidc.com/Linux/2012-02/55500.htm

Getmenuinflater (). Inflate (R.menu.options_menu,menu):
The role of A.inflate is to find out a layout that is defined by XML, but only to find out.
B. The first parameter is the layout, and the second parameter is the menu.

Add a TextView:

1, add the appropriate package

2, declare a textview in Mainactivity.java

3, the text is described in Main.xml, the content is

<textview android:text = "TextView01"android:id= "@+id/textview01" R.java                      can be found  = "Wrap_ Content "=" Wrap_content "=" 61px "=" 69px ">               Note:android:layout_x and Android: Layout_y is only effective in absolutelayout layouts. The general default layout is the LinearLayout layout. </TextView>

1) fill_parent

Setting the layout of a component to fill_parent will force the component to expand to fill as much space as possible within the layout unit. This is roughly the same as the DockStyle property of Windows controls. Setting a top layout or control for Fill_parent will force it to fill the entire screen.

2) wrap_content

Setting the size of a view to Wrap_content will force the view to expand to show the entire content. Take the TextView and ImageView controls as an example, set to Wrap_content to fully display the text and images inside them. Layout elements will change size based on content. Setting the size of a view to Wrap_content is roughly equivalent to setting the AutoSize property of Windows controls to true.

3) Match_parent
Android2.2 in Match_parent and fill_parent is a meaning. Two parameters meaning, match_parent more appropriate, so starting from 2.2 two words can be used. So if you consider the use of the lower version, you need to use fill_parent.

    

Use the Findviewbyid () method to get textview:mtextview01 = (TextView) Findviewbyid in Main.xml (r.id. TEXTVIEW01);

The Findviewbyid () function that we call actually has two kinds (at present I only see two kinds, unsure whether there is no other), one is the activity class in the Findviewbyid () function

The other is the Findviewbyid () function defined in the view class

In general, the (**view) Findviewbyid (r.id.**) that we use in the OnCreate () method is both the Findviewbyid () function in the invoked activity

In other cases, the ***view.findviewbyid () is called the Findviewbyid in the View class (


⑤ Setting TextView label content
⑥ Setting Text hyperlinks
Import Android.widget.TextView;
Private TextView mTextView01;
mTextView01 = (TextView) Findviewbyid (r.id. TEXTVIEW01);
String str_2 = "Welcome to Android TextView World ...";
mTextView01. SetText (str_2)

Add a hyperlink

<textview
Android:id= "@+id/textview02"
Android:layout_width = "Wrap_content"
Android:layout_height = "Wrap_content"
Android:autolink = "All"
Android:text = "Please visit Android Developer:
Http://developer.android.com/index.html ">
</TextView>

Textview_xml parameter: http://blog.csdn.net/wazhl/article/details/7665379

I can see it in Mainactivity.xml again.

Add view this section does not need to add in androidmanifest.xml;?

I'm not a success anyway.

In Androidmanifest.xml there is a

<view
Android:layout_width= "Match_parent"
android:layout_height= "1dip"
android:background= "#696969"/>

This is probably the main interface, but after the deletion, including the relevant code in the Main.xml, run no change .... Dizzy

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.