There are two ways to get a height from a view-provided method:
1, the currently displayed view directly gets the current view width
2, through the activity of GetWindow (). Findviewbyid (window.id_android_content) Gets the view root (is a Framelayout object) currently displayed by the system. The Android drawing will be drawn in the framelayout with the view that will be drawn.
The display object gets the screen width:
Gets the Getwindowmanager (). Getdefaultdisplay () in the Display object activity.
getwidth () returns the width of the display interface, which is the screen width
getheight () Returns the height of the display interface, which is the screen height
Setting the Displaymetrics width value by the display object and getting the screen wide by the Displaymetrics object is a bit superfluous:
getwidth () returns the width of the display interface, which is the screen width
getheight () Returns the height of the display interface, which is the screen height
Some value calculations are commonly used:
High screen width
Canvas objects, display objects, and displaymetrics to get a high screen width
Status bar Height
View Getwindowvisibledisplayframe (Rect outrect) appended Outrect, Outrect.top () is the status bar height
Title Height
The Outrect.height ()-view.getheight () is the caption height after the getwindowvisibledisplayframe (Rect outRect1) value outrect The view is attached.
1. Get Status bar Height:
Decorview is the topmost view in the window, you can get Decorview from windows, and then Decorview has a getwindowvisibledisplayframe method to get to the area that the program displays, including the title bar , but the status bar is not included.
So, we can figure out the height of the status bar.
Copy Code code as follows:
Rect frame = new Rect ();
GetWindow (). Getdecorview (). Getwindowvisibledisplayframe (frame);
int statusbarheight = Frame.top;
2. Get the title bar height:
GetWindow (). Findviewbyid (Window.id_android_content) This method gets to the view that the program does not include the title bar, and then you know the height of the title bar.
Copy Code code as follows:
int contenttop = GetWindow (). Findviewbyid (window.id_android_content). GetTop ();
Statusbarheight is the height of the status bar above
int titlebarheight = Contenttop-statusbarheight