DisplayMetrics display = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(display);
int width = display.widthPixels;
int height = display.heightPixels;
获取layout尺寸
在onDraw方法中获得布局的尺寸:
protect void onDraw(){
...........
int width = getMeasuredWidth(); // 获得布局的实际宽度
int height = getMeasuredHeight(); // 获得布局的实际高度
int left = getLeft();
int right = getRight();
int top = getTop();
int bot = getBottom();
right = right - left;
bot = bot -top;
left = 0;
top = 0;
........
}