(4.1.39)Android屏幕测量:屏幕、状态栏、标题栏
来源:互联网 发布:core keygen for mac 编辑:程序博客网 时间:2024/06/08 11:37
一、基本区域划分
1.1 屏幕区域
以下两种方法在屏幕未显示的时候,还是处于0的状态,即要在setContentView调用之后才有效
WindowManager windowManager = getWindowManager(); Display display = windowManager.getDefaultDisplay(); screenWidth = display.getWidth(); screenHeight = display.getHeight();
DisplayMetrics dm = new DisplayMetrics(); this.getWindowManager().getDefaultDisplay().getMetrics(dm);//this指当前activity screenWidth =dm.widthPixels; screenHeight =dm.heightPixels;
1.2 应用区域的获取
Rect outRect = new Rect(); activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(outRect);
我们可以注意到,应用区域的顶部其实就是状态栏的高度,由此可以得到状态栏高度获取方式:
Rect frame = new Rect(); getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); int statusBarHeight = frame.top;
1.3 view绘制区域获取
Rect outRect = new Rect(); activity.getWindow().findViewById(Window.ID_ANDROID_CONTENT).getDrawingRect(outRect);
我们可以注意到“绘制区域的outRect.top - 应用区域的outRect.top ”其实就是标题栏的高度:
int contentTop = getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop(); //statusBarHeight是上面所求的状态栏的高度 int titleBarHeight = contentTop - statusBarHeight
二、屏幕模式
- 无标题
requestWindowFeature(Window.FEATURE_NO_TITLE);
- 全屏模式
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
- 横屏
setRequesteOrientation(ActivityInfo.SCREEN_ORIENTATION_LADSCAPE);
2.1 全屏无标题示例
用代码方式在我们应用运行后,会看到短暂的状态栏,然后才全屏,而xml配置方法是不会有这种情况的
一、在代码中设置:
public class OpenGl_Lesson1 extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //去除title requestWindowFeature(Window.FEATURE_NO_TITLE); //去掉Activity上面的状态栏 getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN , WindowManager.LayoutParams. FLAG_FULLSCREEN); setContentView(R.layout.main); } }
在这里要强调一点,设置全屏的俩段代码必须在setContentView(R.layout.main) 之前,不然会报错
二、在配置文件里修改
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
阅读全文
0 0
- (4.1.39)Android屏幕测量:屏幕、状态栏、标题栏
- (4.1.39)Android屏幕高度、状态栏高度、标题栏高度
- (4.1.39.1)android 状态栏、标题栏、屏幕高度
- android 状态栏、标题栏、屏幕高度
- android 状态栏、标题栏、屏幕高度
- android 状态栏、标题栏、屏幕高度
- android 状态栏、标题栏、屏幕高度
- android 状态栏、标题栏、屏幕高度
- android 状态栏、标题栏、屏幕高度
- android 状态栏、标题栏、屏幕高度
- Android 状态栏、标题栏、屏幕高度
- Android双击屏幕动态实现全屏(隐藏标题栏状态栏)
- Android屏幕中隐藏标题栏和状态栏
- Android屏幕中隐藏标题栏和状态栏
- android 获取状态栏、标题栏、屏幕高度、宽度
- Android获取屏幕、标题栏、状态栏高度
- Android--获取标题栏,状态栏,屏幕高度
- Android 状态栏,标题栏,屏幕高度获取总结
- 《集体智慧编程》第九章
- 表单标签
- 抽象类和接口的区别
- 文件上传
- 刷题#R5
- (4.1.39)Android屏幕测量:屏幕、状态栏、标题栏
- ios开发之人脸识别(给眼睛打上马赛克)
- nova调用rados来实现snapshot
- ant脚本学习
- 人生的第一篇博客
- Java-异常笔记
- React Native 与 原生交互
- 说说DNS解析在wireshark里抓包内容(一)
- 文件下载