android 获取屏幕中心点

莫邪女郎 2014-10-08 05:52:11
加精
private void method(Canvas canvas) {
// 1.获取屏幕的宽高
WindowManager wm = (WindowManager) m_context
.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics dm = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;

// 2.获取状态栏的高度
Rect frame = new Rect();
getWindowVisibleDisplayFrame(frame);
int stateHeight = frame.top;

// 2.获取图片的宽高
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(m_context.getResources(),
R.drawable.icon_map_center_point, options);
int bit_height = options.outHeight;
int bit_width = options.outWidth;
options.inJustDecodeBounds = false;

// 3.计算屏幕中心点的坐标
int cx = (width - bit_width) / 2;
int cy = (height - stateHeight - bit_height) / 2;
Bitmap bi = BitmapFactory.decodeResource(m_context.getResources(),
R.drawable.icon_map_center_point, options);

canvas.drawBitmap(bi, cx, cy, m_paint);
}
...全文
1925 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
绿领巾童鞋 2014-10-15
  • 打赏
  • 举报
回复
自问自答了。。。。
fhlkm 2014-10-09
  • 打赏
  • 举报
回复
你的问题呢?
nettman 2014-10-09
  • 打赏
  • 举报
回复

566

社区成员

发帖
与我相关
我的任务
社区描述
英特尔® 边缘计算,聚焦于边缘计算、AI、IoT等领域,为开发者提供丰富的开发资源、创新技术、解决方案与行业活动。
社区管理员
  • 英特尔技术社区
  • shere_lin
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧