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