Android in the custom control, often need to get the width of the screen, each time to write, you can directly encapsulate him into a tool class, directly to use, nonsense do not say, directly on the code
/**
* * * * * *
package com.example.customview;
Import Android.content.Context;
Import Android.util.DisplayMetrics;
Import Android.view.WindowManager;
/**
* Get mobile Screen size
* @author
* */public
class Measureutil {
/**
*
* * @return
*/public
static int getwidth (context context) {
WindowManager wm= (WindowManager) Context.getsystemservice (context.window_service);
Displaymetrics outmetrics = new Displaymetrics ();
Wm.getdefaultdisplay (). Getmetrics (outmetrics);
return outmetrics.widthpixels;
}
/**
* High
* @return/public
static int getheight (context context) {
WindowManager wm= ( WindowManager) Context.getsystemservice (context.window_service);
Displaymetrics outmetrics = new Displaymetrics ();
Wm.getdefaultdisplay (). Getmetrics (outmetrics);
Return Outmetrics.heightpixels
}
}