91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Android 獲取設備寬高分辨率

發布時間:2020-06-25 05:36:01 來源:網絡 閱讀:497 作者:FergusJ 欄目:移動開發

想要獲取設備寬高分辨率,最好放到Utils跑龍套里面。


基礎知識:

  1. WindowManager

  • The interface that apps use to talk to the window manager.

  • Use Context.getSystemService(Context.WINDOW_SERVICE) to get one of these.

  • Each window manager instance is bound to a particular Display. To obtain a WindowManager for a different display, use createDisplayContext(Display) to obtain a Context for that display, then use Context.getSystemService(Context.WINDOW_SERVICE) to get the WindowManager.

  • The simplest way to show a window on another display is to create a Presentation.  The presentation will automatically obtain a WindowManager and Context for that display.

    整個Android的窗口機制是基于一個叫做 WindowManager,這個接口可以添加view到屏幕,也可以從屏幕刪除view。它面向的對象一端是屏幕,另一端就是View,直接忽略我們以前的Activity或者Dialog之類的東東。其實我們的Activity或者Diolog底層的實現也是通過WindowManager,這個 WindowManager是全局的,整個系統就是這個唯一的東東。它是顯示View的最底層了。 (引自http://gundumw100.iteye.com/blog/830235)


方法:

abstract Display

getDefaultDisplay()

Returns the Display upon which this WindowManager instance will create new windows.

abstract voidremoveViewImmediate(View view)

Special variation of removeView(View) that immediately invokes the given view hierarchy's View.onDetachedFromWindow() methods before returning.

2.Display

Provides information about the size and density of a logical display.

The display area is described in two different ways.

  • The application display area specifies the part of the display that may contain an application window, excluding the system decorations.  The application display area may be smaller than the real display area because the system subtracts the space needed for decor elements such as the status bar.  Use the following methods to query the application display area: getSize(Point), getRectSize(Rect) and getMetrics(DisplayMetrics).

  • The real display area specifies the part of the display that contains content including the system decorations.  Even so, the real display area may be smaller than the physical size of the display if the window manager is emulating a smaller display using (adb shell am display-size).  Use the following methods to query the real display area: getRealSize(Point), getRealMetrics(DisplayMetrics).


A logical display does not necessarily represent a particular physical display device such as the built-in screen or an external monitor.  The contents of a logical display may be presented on one or more physical displays according to the devices that are currently attached and whether mirroring has been enabled.



下面給出代碼:

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;

public class Utils {

	public static int getScreenWidth(Context context) {
		WindowManager manager = (WindowManager) context
				.getSystemService(Context.WINDOW_SERVICE);
		Display display = manager.getDefaultDisplay();
		return display.getWidth();
	}

	public static int getScreenHeight(Context context) {
		WindowManager manager = (WindowManager) context
				.getSystemService(Context.WINDOW_SERVICE);
		Display display = manager.getDefaultDisplay();
		return display.getHeight();
	}

	public static float getScreenDensity(Context context) {
		try {
			DisplayMetrics dm = new DisplayMetrics();
			WindowManager manager = (WindowManager) context
					.getSystemService(Context.WINDOW_SERVICE);
			manager.getDefaultDisplay().getMetrics(dm);
			return dm.density;
		} catch (Exception ex) {

		}
		return 1.0f;
	}

}










向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

淮阳县| 普宁市| 柳江县| 洛阳市| 扬中市| 松阳县| 略阳县| 屯门区| 城市| 北票市| 海盐县| 武清区| 金塔县| 建昌县| 七台河市| 灵璧县| 宜昌市| 应城市| 城口县| 木兰县| 壶关县| 成都市| 喀喇沁旗| 元朗区| 瓦房店市| 牟定县| 北票市| 龙江县| 岗巴县| 钟祥市| 北碚区| 双流县| 石林| 上杭县| 汝南县| 临桂县| 宣恩县| 汉中市| 崇左市| 罗定市| 安溪县|