首页 > 移动平台 > 详细

android 获取屏幕宽高 和 获取控件坐标

时间:2014-12-22 11:14:52      阅读:189      评论:0      收藏:0      [点我收藏+]

一.获取屏幕宽高:

(1).
WindowManager wm = (WindowManager)getSystemService(Context.WINDOW_SERVICE);
int width = wm.getDefaultDisplay().getWidth();
int height = wm.getDefaultDisplay().getHeight();
(2).
WindowManager wm = this.getWindowManager();
int width = wm.getDefaultDisplay().getWidth();
int height = wm.getDefaultDisplay().getHeight();

二.获取控件的坐标:

int[] location = new int[2];  
t.getLocationOnScreen(location);  
int x = location[0];  
int y = location[1];  
System.out.println("x:"+x+"y:"+y);  
System.out.println("图片各个角Left:"+t.getLeft()+"Right:"+t.getRight()+"Top:"+t.getTop()+"Bottom:"+t.getBottom()); 

android 获取屏幕宽高 和 获取控件坐标

原文:http://blog.csdn.net/binrong112558058/article/details/42076429

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!