Get the high-width of the phone screen in the Onwindowfocuschanged method

Source: Internet
Author: User

When developing, we often get high-width data from the phone's screen. Usually we will write a fetch method such as Getscreen () and then call the Getscreen () method in OnCreate (). The result we may get is the width of the height of 0. What is this for? The reason is:

In the activity life cycle, Oncreate,onstart, onresume are not real screen visible (visible) point-in-time, real visible The point in time is when the onwindowfocuschanged () function is executed, at which point the user can really interact with the app, and the user's actions are limited until the function is called. So we have to get to the phone screen of the width of the high, is to be executed in the Onwindowfocuschanged () method.

@Override
public void Onwindowfocuschanged (Boolean hasfocus) {
int width=getresources (). Getdisplaymetrics (). widthpixels;//Screen Width
int hight=getresources (). Getdisplaymetrics (). heightpixels;//screen Height
Super.onwindowfocuschanged (Hasfocus);
}

 

Get the high-width of the phone screen in the Onwindowfocuschanged method

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.