Android layout and intent notes and common instances

Source: Internet
Author: User

Today, I started to get familiar with Android upper-layer applications. I have no choice but to go back to the market-_-|

 

Three Common Layout methods:Linearlayout (linear layout), tablelayout? (Table layout), relative layout (relative layout ).

 

The layout is more casual than the previous two layout methods. You can place the control wherever you want.

Common commands in linearlayout and tablelayout are:

Android: id -- control specifies the corresponding ID
Android: Text -- display text in the control. Use strings. xml whenever possible
Android: gravity-the basic text location in the control, such as center, left, right, and center_horizontal.
Android: textsize -- the font size in the control, in PT.
Android: background -- control background color
Android: width -- control width
Android: height -- control height
Android: padding: the padding of a space, which refers to the distance from the content in the control to the space. Android: padding_left, Android: padding_right, and so on.
Android: siglelise -- if it is set to true, the control content will be displayed in the same line.
Android: margin -- margin.

 

Relative layout: relative Layout

Android: layout_above -- place the control bottom above the given control
Android: layout_below -- place the top of the control under the given control
Android: layout_toleftof -- move the left edge of the control to the right of the given control
Android: layout_torightof -- move the left edge of the control to the right of the given control
Android: layout_alignbaseline -- align the baseline of the control with the baseline of the specified control.
Android: layout_alignleft -- align the left side of the control with the left side of the control.
Android: layout_alignright -- align the right of the control with the right of the specified control.
Android: layout_aligntop -- align the top of the control with the top of the specified control.

Android: layout_alignparentbottom -- true: the control is aligned with the parent control.
Android: layout_centerhorizontal -- true, and the space is centered horizontally.
Android: layout_centerinparent -- true. For the horizontal/vertical center of the parent control.
Android: layout_centervertural -- is placed in the center of the vertical direction.

 

 

 

Intent-Filter
1 Android. Intent. Action. Main determines the activity that the application starts first.
2 Android. Intent. Category. launcher determines whether the application is displayed in the program list.

Intent calls the application
Example: Call the Google Browser
Uri uri = URI. parse ("http://www.android123.com.cn ");
Intent it = new intent (intent. action_view, Uri );
Startactivity (it );

Common application calls

Display web pages:

1. Uri uri = URI. parse ("http://www.android123.com.cn ");
2. Intent it = new intent (intent. action_view, Uri );
3. startactivity (it );

Show Google maps:

1. Uri uri = URI. parse ("Geo: 38.899533,-77.036476 ");
2. Intent it = new intent (intent. action_view, Uri );
3. startactivity (it );

Maps Path Planning:

1. Uri uri = URI. parse ("http://maps.google.com/maps? F = D & saddr = startlat % 20 startlng & daddr = endlat % 20 endlng & HL = EN ");
2. Intent it = new intent (intent. action_view, Uri );
3. startactivity (it );

Call number:
1. Uri uri = URI. parse ("Tel: xxxxxx ");
2. Intent it = new intent (intent. action_dial, Uri );
3. startactivity (it );

1. Uri uri = URI. parse ("Tel. xxxxxx ");
2. Intent it = new intent (intent. action_call, Uri );

Note that you need the permission <uses-Permission id = "android. Permission. call_phone"/>

Send SMS/MMS

1. Intent it = new intent (intent. action_view );
2. it. putextra ("sms_body", "Welcome to Android Development Network ");
3. It. settype ("Vnd. Android-DIR/MMS-SMS ");
4. startactivity (it );

Send SMS

1. Uri uri = URI. parse ("smsto: 10086 ");
2. Intent it = new intent (intent. action_sendto, Uri );
3. It. putextra ("sms_body", "10086"); // The body is 10086
4. startactivity (it );

Send MMS

1. uri uri = Uri. parse ("content: // media/external/images/Media/10"); // This URI is modified based on the actual situation. External indicates that external storage is sdcard.
2. Intent it = new intent (intent. action_send );
3. It. putextra ("sms_body", "android123.com.cn ");
4. It. putextra (intent. extra_stream, Uri );
5. It. settype ("image/PNG ");
6. startactivity (it );
Send email

2. Uri uri = URI. parse ("mailto: android123@163.com ");
3. Intent it = new intent (intent. action_sendto, Uri );
4. startactivity (it );

1. Intent it = new intent (intent. action_send );
2. it. putextra (intent. extra_email, "android123@163.com ");
3. It. putextra (intent. extra_text, "android development network test ");
4. It. settype ("text/plain ");
5. startactivity (intent. createchooser (IT, "select an email client "));

1. Intent it = new intent (intent. action_send );
2. String [] TOS = {"android123@163.com"}; // send
3. String [] CCS = {"ophone123@163.com"}; // CC
4. It. putextra (intent. extra_email, TOS );
5. It. putextra (intent. extra_cc, CCS );
6. It. putextra (intent. extra_text, "body ");
7. It. putextra (intent. extra_subject, "title ");
8. It. settype ("message/rfc822"); // encoding type
9. startactivity (intent. createchooser (IT, "select an email client "));

Add attachments by email

1. Intent it = new intent (intent. action_send );
2. it. putextra (intent. extra_subject, "body ");
3. It. putextra (intent. extra_stream, "file: // sdcard/nobody.pdf"); // the attachment is the nobody MP3 file on the SD card.
4. sendintent. settype ("audio/MP3 ");
5. startactivity (intent. createchooser (IT, "select an email client "));

Play multimedia

1.
2. Intent it = new intent (intent. action_view );
3. Uri uri = URI. parse ("file: // sdcard/nobody.mp3 ");
4. It. setdataandtype (Uri, "audio/MP3 ");
5. startactivity (it );

1. Uri uri = URI. withappendedpath (mediastore. Audio. Media. internal_content_uri, "1"); // calls the play from the mediaprovider index in the system
2. Intent it = new intent (intent. action_view, Uri );
3. startactivity (it );

Uninstall uninstall the program

1. Uri uri = URI. fromparts ("package", packagename, null); // packagenameis the package name, such as com.android123.apk Installer
2. Intent it = new intent (intent. action_delete, Uri );
3. startactivity (it );

Enter the contact page

Intent intent = new intent ();
Intent. setaction (intent. action_view );
Intent. setdata (people. content_uri );
Startactivity (intent );

View a contact. Of course, this is action_view. If you select and change the Return Action to action_pick, startactivityforresult is required for intent processing.

Uri personuri = contenturis. withappendedid (people. content_uri, ID); // The last Id parameter is the database baseid in the contact provider, that is, the row
Intent intent = new intent ();
Intent. setaction (intent. action_view );
Intent. setdata (personuri );
Startactivity (intent );

Select an image

Intent intent = new intent (intent. action_get_content );
Intent. addcategory (intent. category_openable );
Intent. settype ("image /*");
Startactivityforresult (intent, 0 );

Call the camera of the Android device and set the storage location after taking the photo

Intent intent = new intent (mediastore. action_image_capture );
Intent. putextra (mediastore. extra_output, Uri. fromfile (new file (Environment
. Getexternalstoragedirectory (). getabsolutepath () + "/cwj", android123 + ". jpg"); // save it to the cwjfolder on the sdcard card. The file name is in android123.jpg format.
Startactivityforresult (intent, 0 );

 

Custom activity call

Intent intent = new intent ();
Intent. setclass (dataactivity. This, test3.class );
Startactivity (intent );
Pay attention to the package declaration and permission modification, that is, the modification of androidmanifest. xml!

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.