Android Common Knowledge Notes

Source: Internet
Author: User

1. Android Image Adaptive

Android from 1.6 and higher, Google has added auto-fit functionality to facilitate the porting of various resolution models to developers
<supports-screens
Android:largescreens= "true"
Android:normalscreens= "true"
Android:smallscreens= "true"
Android:anydensity= "true"/>

2./* Get screen pixel and screen density */

Displaymetrics metrics=New displaymetrics ();

Getwindowmanager (). Getdefaultdisplay (). Getmetrics (metrics);

int width=metrics.widthpixels;

int height=metrics.heightpixels;

float density=metrics.density;

int densitydpi=metrics.densitydpi;

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

4. Read the phone book

Androidmanifest.xml

<uses-permission android:name="Android.permission.READ_CONTACTS"></uses-permission>

Java File:

Public void onCreate (Bundle savedinstancestate) {

Super. OnCreate (savedinstancestate);

Setcontentview (r.layout.activity_contacts);

TextView TV = new TextView (this);

TextView TV = (TextView) Findviewbyid (R.ID.TEXTVIEWC1);

String string = "Contact is as follows: \ n";

Try {

Get Contentresolver Object

Contentresolver contentresolver = Getcontentresolver ();

Get the cursor for starting an item in the phone book

cursor cursor = Contentresolver.query (

Contactscontract.contacts. Content_uri, null, null, null,

null);

Move Cursor Down

while (Cursor.movetonext ()) {

Get Name of contact person

int namefieldcolumnindex = cursor

. Getcolumnindex (Phonelookup. Display_name);

String contract = cursor.getstring (Namefieldcolumnindex);

Get phone number

intnumberfieldcolumnindex = cursor

. Getcolumnindex (Phonelookup. number); String number =

Cursor.getstring (Numberfieldcolumnindex);

string + = contract + "\ n";

}

Cursor.close ();

Tv.settext (string);

Setcontentview (TV);

} catch (Exception e) {

E.printstacktrace ();

Log. I (TAG, e.tostring ());

}

}

5, Window switch public void onCreate (bundlesavedinstancestate) {

Super. OnCreate (savedinstancestate);

Setcontentview (r.layout. Activity_01);

Log. I (TAG, "onCreate");

Button button1 = (button) Findviewbyid (r.id. Button11);

/* Listen for the button's event information */

Button1.setonclicklistener (new Button.onclicklistener () {

Public void OnClick (View v) {

Create a new Intent object

Intent Intent = new Intent ();

Specifies the class to start intent

Intent.setclass (Activity01. this, Activity02. class);

Start a new activity

StartActivity (Intent);

Close the current Activity

Activity01. this. Finish ();

}

});

}

6, Android.intent.action.MAIN determines the activity that the application starts first, Android.intent.category.LAUNCHER determines whether the application appears in the program list. Main and launcher are also set to make sense

Android Common Knowledge Notes

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.