获取控件相对于屏幕的坐标
View view = findViewById(R.id.button1);
int[] locations = new int[2];
view.getLocationOnScreen(locations);
int x = locations[0];
int y = locations[1];
截图并保存成png
View view = getLayoutInflater().inflate(R.layout.main, null);
//打开图像缓存
view.setDrawingCacheEnabled(true);
//必须调用measure和layout方法才能成功保存可视组件的截图到png
//测量view的大小
view.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
//发送位置和尺寸到view及其所有的子view
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
try
{
Bitmap bitmap = view.getDrawingCache();
FileOutputStream fos = new FileOutputStream("/sdcard/test.png");
bitmap.compress(CompressFormat.PNG, 100, fos);
fos.close();
}
catch (Exception e)
{
}
//获取屏幕
View ScreenView = getWindow().getDecorView();
该view包括整个屏幕(状态栏和标题栏)。