Android Development Tips Summary (iii)

Source: Internet
Author: User

1. Press the return key in the interface to determine the visibility of a control, if visible, animate it to disappear, and the app does not exit.

In the OnKeyDown method:

if (keycode = = 4) {

if (slidingmenu.getvisibility () = = view.visible) {

Exiting animations

Animationset animationset = new Animationset (true);

translateanimation animation = new Translateanimation (0,-280, 0, 0);

Animation.setduration (500);

Animationset.addanimation (animation);

Slidingmenu.startanimation (Animationset);

Slidingmenu.setvisibility (View.gone);

return true; If the control is visible in the interface, press the back key to make it disappear, and the app does not exit

}

}

2. Delay jump in Control interface

public class Welcomeactivity extends activity{

Private Handler Mhandler = new Handler () {

public void Handlemessage (Android.os.Message msg) {

Gomain ();

}};

@Override

protected void OnCreate (Bundle savedinstancestate) {

Super.oncreate (savedinstancestate);

Setcontentview (R.layout.welcome);

}

@Override

protected void Onresume () {

Super.onresume ();

Mhandler.sendemptymessagedelayed (0, 3000);

}

/**

* Skip to main interface

*/

private void Gomain () {

Intent Intent = new Intent (welcomeactivity.this, Mainactivity.class);

StartActivity (Intent);

This.finish ();

}}

3. Get screen width and height

Displaymetrics dm = new Displaymetrics ();
This.getwindowmanager (). Getdefaultdisplay (). Getmetrics (DM);
ScreenWidth = Dm.widthpixels;
ScreenHeight = Dm.heightpixels;

The difference between the 4.private protected public

Public
Public, plus this modified class or attribute, can be accessed in the same package or in another package

Private
Private, with this modified class or attribute, can only be accessed in the same category, the same package and other packages cannot be accessed

Protected
Protection, plus this decorated class or attribute, can only be accessed in homogeneous and identical packages, other packages cannot access

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.