另一种方法是使用WindowManager来获取Display对象,然后调用getSize()或getRealSize()方法来获取屏幕尺寸。需要注意的是,getSize()方法获取的是不包括状态栏和导航栏的屏幕大小,而getRealSize()方法(在Android 4.2及以上版本中可用)获取的是包括状态栏和导航栏在内的真实屏幕尺寸。 java public int getScreenHeightUsing...
// The full screen needs to get the height through this method screenHeight = DisplayUtils.getScreenRealHeight(getContext()); } else { screenHeight = DisplayUtils.getScreenHeight(getContext()); } 复制代码 1. 2. 3. 4. 5. 6. 7. 2. 获取屏幕宽度 private fun getScreenWidth(context: Con...
打开activity_main.xml文件,添加如下代码: <LinearLayoutxmlns:android="xmlns:tools="android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"android:padding="16dp"tools:context=".MainActivity"><TextViewandroid:id="@+id/screenHeightTextView"android:layout_width...
(WindowManager)context.getSystemService(Context.WINDOW_SERVICE):(WindowManager)context.getSystemService(Context.WINDOW_SERVICE);if(windowManager==null){returngetScreenHeight(context);}Displaydisplay=windowManager.getDefaultDisplay();Pointpoint=newPoint();display.getRealSize(point);mRealSizes[orientation]=point...
activity.getWindow().findViewById(Window.ID_ANDROID_CONTENT).getDrawingRect(rectangle);returnrectangle.height(); }/*** 可以利用getScreenHeight() 与 getScreenHeight3() 返回值的差异来判断是否存在虚拟导航栏 *@paramcontext *@return*/publicstaticbooleanhasNavigationBar(Context context) {returngetScreenHe...
含有底部导航栏的手机通过以下方法获取高度总是少一截 staticintgetScreenHeight(Context context){DisplayMetrics metrics=context.getResources().getDisplayMetrics();returnmetrics.heightPixels;} 解决方法 publicstaticintgetScreenHeight(Context context){DisplayMetrics displayMetrics=context.getResources().getDisplayMetrics...
intheight = wm.getDefaultDisplay().getHeight(); (二)获得当前view在屏幕中的坐标 int[] location = new int[2]; view.getLocationOnScreen(location); 这样就可以得到该视图在全局坐标系中的x,y值,(注意这个值是要从屏幕顶端算起,也就是索包括了通知栏的高度)//获取在当前屏幕内的绝对坐标 ...
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 * by ...
public static int getScreenWidth() { return Resources.getSystem().getDisplayMetrics().widthPixels; } public static int getScreenHeight() { return Resources.getSystem().getDisplayMetrics().heightPixels; } 注意:如果你想要高度包括导航栏,使用下面的方法WindowManager windowManager =...
通过Display的getHeight()方法,该方法在Android4.1(API16)已经被弃用,用Display的getSize(Point outSize)方法代替。 @Deprecated private static int getScreenHeight(Context context) { return getDisplay(context).getHeight(); } 通过Display的getSize(Point outSize)方法。 private static int getScreenHeight(Contex...