Android in the custom control, often need to get the width of the screen height, every time to write, you can directly encapsulate him as a tool class, directly to use, nonsense, not to say, directly on the code
/** * */package com.example.customview;import android.content.context;import android.util.DisplayMetrics; Import android.view.windowmanager;/** * Get phone screen size * @author * */public class Measureutil {/** * w * @return */public St atic int GetWidth (context context) {WindowManager wm= (windowmanager) Context.getsystemservice (context.window_service );D isplaymetrics outmetrics = new Displaymetrics (); Wm.getdefaultdisplay (). Getmetrics (outmetrics); return Outmetrics.widthpixels;} /** * High * @return */public static int getheight (context context) {WindowManager wm= (WindowManager) Context.getsystemservic E (context.window_service);D isplaymetrics outmetrics = new Displaymetrics (); Wm.getdefaultdisplay (). GetMetrics ( Outmetrics); return outmetrics.heightpixels;}}
Android Get phone screen size