android--获取屏幕高宽度工具类
//获得屏幕相关的辅助类
public class ScreenUtils
{
private ScreenUtils()
{
/* cannot be instantiated */
throw new UnsupportedOperationException("cannot be instantiated");
} /**
* 获得屏幕宽度
*
* @param context
* @return
*/
public static int getScreenWidth(Context context)
{
WindowManager wm = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics outMetrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(outMetrics);
return outMetrics.widthPixels;
} /**
* 获得屏幕高度
*
* @param context
* @return
*/
public static int getScreenHeight(Context context)
{
WindowManager wm = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics outMetrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(outMetrics);
return outMetrics.heightPixels;
} /**
* 获得状态栏的高度
*
* @param context
* @return
*/
public static int getStatusHeight(Context context)
{ int statusHeight = -1;
try
{
Class<?> clazz = Class.forName("com.android.internal.R$dimen.xml");
Object object = clazz.newInstance();
int height = Integer.parseInt(clazz.getField("status_bar_height")
.get(object).toString());
statusHeight = context.getResources().getDimensionPixelSize(height);
} catch (Exception e)
{
e.printStackTrace();
}
return statusHeight;
} /**
* 获取当前屏幕截图,包含状态栏
*
* @param activity
* @return
*/
public static Bitmap snapShotWithStatusBar(Activity activity)
{
View view = activity.getWindow().getDecorView();
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap bmp = view.getDrawingCache();
int width = getScreenWidth(activity);
int height = getScreenHeight(activity);
Bitmap bp = null;
bp = Bitmap.createBitmap(bmp, 0, 0, width, height);
view.destroyDrawingCache();
return bp; } /**
* 获取当前屏幕截图,不包含状态栏
*
* @param activity
* @return
*/
public static Bitmap snapShotWithoutStatusBar(Activity activity)
{
View view = activity.getWindow().getDecorView();
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap bmp = view.getDrawingCache();
Rect frame = new Rect();
activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
int statusBarHeight = frame.top; int width = getScreenWidth(activity);
int height = getScreenHeight(activity);
Bitmap bp = null;
bp = Bitmap.createBitmap(bmp, 0, statusBarHeight, width, height
- statusBarHeight);
view.destroyDrawingCache();
return bp; } }
android--获取屏幕高宽度工具类的更多相关文章
- Android获取屏幕的宽度和高度(dp)
public void getAndroiodScreenProperty() { WindowManager wm = (WindowManager) this.getSystemService(C ...
- Android获取屏幕宽和高
android获取屏幕的高度和宽度用到WindowManager这个类,两种方法: 1.WindowManager wm = (WindowManager) getContext() ...
- android之获取屏幕的宽度和高度
获取屏幕的宽度和高度: 方法一: //获取屏幕的宽度 public static int getScreenWidth(Context context) { WindowManager manager ...
- LongLightUtils【保持屏幕常亮工具类】
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 这里只是简单记录下保持屏幕常亮工具类LongLightUtils的使用,具体请阅读参考资料<Android屏幕常亮,其实很简单 ...
- Android获取屏幕大小和设置无标题栏
android获取屏幕大小非常常用,例如写个程序,如果要做成通用性很强的程序,适用屏幕很强,一般布局的时候都是根据屏幕的长宽来定义的,所以我把这个总结一下,方便日后忘记的时候查阅.还有就是有时候写程序 ...
- Android 获取屏幕分辨率
原文:Android 获取屏幕分辨率 得到一个屏幕尺寸的三种方法如下: // 通过WindowManager获取 DisplayMetrics dm = new Displ ...
- Android 获取屏幕大小和密度
Android 获取屏幕大小和密度 DisplayMetrics metric = new DisplayMetrics(); getWindowManager().getDefaultDisplay ...
- Android获取屏幕大小
本来想着如下方法就能得到了 Display display = getWindowManager().getDefaultDisplay(); Log.i("view", &quo ...
- Android开发之常用必备工具类图片bitmap转成字符串string与String字符串转换为bitmap图片格式
作者:程序员小冰,CSDN博客:http://blog.csdn.net/qq_21376985 QQ986945193 博客园主页:http://www.cnblogs.com/mcxiaobing ...
随机推荐
- ES使用org.elasticsearch.client.transport.NoNodeAvailableException: No node available 错误解决方法
1) 端口错 client = new TransportClient().addTransportAddress(new InetSocketTransportAddress(ipAddress, ...
- linux下的进程(孤儿进程、僵尸进程)
linux提供了一种机制可以保证只要父进程想知道子进程结束时的状态信息,就可以得到.这种机制就是:在每个进程退出的时候,内核释放该进程所有的资源,包括打开文件,占用的内存等.但是仍然为其保留一定的信息 ...
- 推荐几个 WebSocket 服务端实现
http://netty.io/http://socket.io/https://github.com/StackExchange/NetGainhttps://github.com/SignalR/ ...
- FineBI学习系列之FineBI的ETL处理(图文详解)
不多说,直接上干货! 这是来自FineBI官网提供的帮助文档 http://help.finebi.com/http://help.finebi.com/doc-view-48.html 目录: 1. ...
- Spring Security OAuth2实现单点登录
1.概述 在本教程中,我们将讨论如何使用 Spring Security OAuth 和 Spring Boot 实现 SSO(单点登录). 本示例将使用到三个独立应用 一个授权服务器(中央认证机制) ...
- Spring Boot + Spring Cloud 实现权限管理系统 后端篇(五):模块化切分
切分工程 考虑到后续我们的模块会越来越多,依赖的公共代码和配置需要集中管理,我们在这里先把公共模块和配置从后台管理业务中剥离出来. 新增两个工程,切分后结构如下: kitty-boot:启动器及全局配 ...
- redis cluster集群管理工具redis-trib.rb命令小结-运维笔记
redis-trib.rb是redis官方推出的管理redis集群的工具,集成在redis的源码src目录下,是基于redis提供的集群命令封装成简单.便捷.实用的操作工具.redis-trib.rb ...
- JS作用域,作用域,作用链详解
前言 通过本文,你大概明白作用域,作用域链是什么,毕竟这也算JS中的基本概念. 一.作用域(scope) 什么是作用域,你可以理解为你所声明变量的可用范围,我在某个范围内申明了一个变量,且这个变量 ...
- zoj 2723 Semi-Prime(素筛打表+搜索优化)
题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2723 题目描述: Prime Number Definitio ...
- C# WebApi 返回JSON
在默认情况下,当我们新建一个webapi项目,会自动返回XML格式的数据,如果我们想返回JSON的数据,可以设置下面的三种方法. 1. 不用改配置文件,在Controller的方法中,直接返回Http ...