Android Rookie-Learn note 1

Source: Internet
Author: User

1: Each activity class must be mapped in a androidmanifest.xml file. Otherwise null pointer exception.


The res directory of the 2:android is fixed and can only be of the following types:drawable,layout,values,xml,raw, Color

If you add a different directory, it will report the error ' Invalid resource directory name ',

3: Launch Android project, the app apk file will be generated in the bin directory.


4:res-drawable Analysis

DRAWABLE-HDPI high-resolution picture; drawable-mdpi place a medium-resolution picture; drawable-ldpi place a low-resolution picture

5: View Usage
(1) How to define a view in an XML file:
There is a res/layout directory under the source directory of the Android project, which is used to store the layout files.
Layout files are typically named after the activity's name, with. xml as the suffix.
When creating a component in XML, you need to specify an ID for the component, such as: The android:id= "@+id/name" system automatically creates the corresponding R resource class variable in the Gen directory.

(2) How to use views in activity:
When you create each activity in your code, you typically call Setcontentview () in the OnCreate () method to load the specified XML layout file.
You can then use Findviewbyid () to get a control of the corresponding ID created in the layout file, such as a button.
Such as:

Private Button Btnsndmag;
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Loading main.xml layout files
Setcontentview (R.layout.main);
Find the button component for with ID
Btnsndmag = (Button) This.findviewbyid (R.ID.BTNSNDMAG);
....
}

6: Five major layouts
LinearLayout (linear layout),
Framelayout (single frame layout),
Absolutelayout (absolute layout),
Tablellayout (table layout),
Relativelayout (relative layout).
The most commonly used ones are linearlayout, Tablellayout and Relativelayout.
These layouts can be used in nested nesting.

Android Rookie-Learn note 1

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.