Say hello to Android.

Source: Internet
Author: User

Developing an Android app takes about three steps:
1. Create an Android project
2. Defining the application's user interface in an XML layout file
3. Writing a business implementation in Java code


Writing HelloWorld Programs

The first is to modify the Main.xml file in the Res directory, the layout of the application interface.
Linear layout: Linerlayout
Table layout: Tablelayout
Relative layout: relativelayout
Absolute layout: Absolutelayout
Frame layout: Framelayout

Android:width the width of the specified control
Android:height the height of the specified control
The difference between Android layouts--android fill_parent, wrap_content, and Match_parent

Three properties are used to fit the horizontal or vertical size of the view, and a layout based on the contents or dimensions of the view is more convenient than specifying the view range precisely.

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.

hardcoded string,should use @string resource warning && All classes used for one-time import in Eclipse && renaming text objects in multiple calls && renaming package names
When using Eclipse's in the layout file, sometimes editing the string names of some controls, sometimes prompting warnings such as "hardcoded string" Next ", should use @string resource", what's the reason?

[HTML] View plaincopy on code to see a snippet derived from my Code slice
<button
Android:id= "@+id/button1"
Android:layout_width= "118DP"
android:layout_height= "Wrap_content"
android:text= "Next"/> "
While the above practices can work correctly, this is not a good habit and should be set in Res/values/strings.xml:

[HTML] View plaincopy on code to see a snippet derived from my Code slice
<?xml version= "1.0" encoding= "Utf-8"?>
<resources>
<string name= "Message" > Next </string>
</resources>
Use when quoting: android:text= "@string/message" on the line. This can be done to change the whole change, in support of multiple languages is also very useful. If you do not want to edit the Strings.xml file, use the Layout box, click the control's TextView item, new string name, and then refine the corresponding content in the strings.xml corresponding edit box.
=====================================================================================================

Using key combinations: Ctrl+shift+o can import all classes that require import at once.

=======================================================================================================

A particular object name may be called multiple times in a Java file, and if you want to modify the name of the object, you can double-click the object in Eclipse to display all calls to it. Then right-click to select Refactor->rename.

=======================================================================================================
APK App project folder first name, you can directly modify the name, right-click the project, select Refactor->rename can

An error occurred while modifying Sring.xml
Multiple annotations found at the line:
-Error:error parsing Xml:not well-formed
(Invalid token)
-Content is not allowed in trailing section

Later found to be
Messagemessage<?xml version= "1.0" encoding= "Utf-8"?>
<resources>
<string name= "App_name" >HelloWorld</string>
<string name= "Hello_world" >hello world!</string>
<string name= "Ages" >dianji</string>
<string name= "Action_settings" >Settings</string>
</resources>
There are two more message in the beginning of the program, which should be inadvertently copied to the resulting. It will be fine if you delete it later. Note the specification of the XML file.

When writing the business code, you need to use the package that the listener must have in the beginning of the program, otherwise the bug
Import Android.os.Bundle;
Import Android.view.View;
Import Android.widget.Button;
Import Android.widget.TextView;
Import Android.view.View.OnClickListener;


Bn.setonclicklistener (New Onclicklistener ()
{

@Override
public void OnClick (View v)
{
Final TextView show = (TextView) Findviewbyid (r.id.show);
Show.settext ("Hello android---" +new java.util.Date ());

}
});

Attachment is the program packaged into the APK file, placed in Http://yunpan.cn/cJ4wEIk4mq7KZ access password 8390

Say hello to 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.