{"id":813,"date":"2015-07-01T10:55:12","date_gmt":"2015-07-01T02:55:12","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=813"},"modified":"2026-08-18T12:58:42","modified_gmt":"2026-08-18T04:58:42","slug":"%e8%8e%b7%e5%8f%96%e5%b1%8f%e5%b9%95%e3%80%81%e6%8e%a7%e4%bb%b6%e5%a4%a7%e5%b0%8f%e6%96%b9%e6%b3%95%e6%b1%87%e6%80%bb","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=813","title":{"rendered":"\u83b7\u53d6\u5c4f\u5e55\u3001\u63a7\u4ef6\u5927\u5c0f\u65b9\u6cd5\u6c47\u603b"},"content":{"rendered":"<section id=\"wenyan\" style=\"font-family: system-ui, 'Apple Color Emoji', 'Segoe UI', 'Segoe UI Symbol', 'Noto Sans', Roboto, sans-serif; line-height: 1.75; font-size: 16px; color: #000000; caret-color: #000000;\" data-provider=\"WenYan\">\n<blockquote style=\"margin: 20px 0px; display: block; font-size: 0.9em; overflow: auto; border-left: 3px solid #ef7060; color: #6a737d; padding: 10px 10px 10px 20px; background: #fff9f9;\">\n<p style=\"margin: 1em 0px;\">\u5728 Android \u91cc\u91cf\u63a7\u4ef6\u5bbd\u9ad8\uff0c<code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">onCreate<\/code> \u91cc\u76f4\u63a5 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">getHeight()<\/code> \/ <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">getMeasuredWidth()<\/code> \u7ecf\u5e38\u662f <strong>0<\/strong>\uff1a\u754c\u9762\u8fd8\u6ca1\u8d70\u5b8c measure \/ layout\u3002\u672c\u6587\u6c47\u603b\u63a7\u4ef6\u3001\u72b6\u6001\u680f\u3001\u6807\u9898\u680f\u3001\u5c4f\u5e55\u548c\u5185\u5bb9\u533a\u7684\u53d6\u6cd5\uff0c\u5e76\u7528 PopupWindow \u628a\u8fd9\u4e9b\u5c3a\u5bf8\u4e32\u8d77\u6765\u3002<\/p>\n<\/blockquote>\n<p><!--more--><\/p>\n<hr>\n<h2 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em; border-bottom: 2px solid #ef7060; display: flex;\"><span style=\"display: inline-block; font-weight: bold; background: #ef7060; color: #ffffff; padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;\">\u4e00\u3001\u4e3a\u4ec0\u4e48 onCreate \u91cc\u62ff\u4e0d\u5230\u5c3a\u5bf8<\/span><\/h2>\n<p style=\"margin: 1em 0px;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">onCreate<\/code> \u53ea\u8d1f\u8d23\u6570\u636e\u521d\u59cb\u5316\uff0c\u63a7\u4ef6\u8fd8\u6ca1\u771f\u6b63\u7ed8\u5236\uff1b\u7b49\u5230 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">onDraw<\/code> \u518d\u91cf\u53c8\u592a\u665a\u3002\u6b63\u786e\u65f6\u673a\u662f\uff1ameasure \/ layout \u521a\u5b8c\u6210\u3001\u7ed8\u5236\u4e4b\u524d\u3002\u53ef\u7528 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">ViewTreeObserver<\/code> \u6216 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">View.post()<\/code> \u5361\u4f4f\u8fd9\u4e00\u62cd\u3002<\/p>\n<table style=\"border-collapse: collapse; margin: 1.4em auto; max-width: 100%; table-layout: fixed; text-align: left; overflow: auto; display: table; overflow-wrap: break-word; word-break: break-all;\" width=\"817\">\n<thead>\n<tr>\n<th style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top; font-weight: bold; background-color: #fff9f9; color: #ef7060;\">\u65b9\u6cd5<\/th>\n<th style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top; font-weight: bold; background-color: #fff9f9; color: #ef7060;\">\u65f6\u673a<\/th>\n<th style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top; font-weight: bold; background-color: #fff9f9; color: #ef7060;\">\u6ce8\u610f<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">OnPreDrawListener<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u7ed8\u5236\u524d<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u53ef\u80fd\u53cd\u590d\u56de\u8c03\uff0c\u7528 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">hasMeasured<\/code> \u53ea\u7b97\u4e00\u6b21<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">OnGlobalLayoutListener<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u5168\u5c40 layout \u5b8c\u6210<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u540c\u6837\u53ef\u80fd\u591a\u6b21\u89e6\u53d1\uff0c\u91cf\u5b8c\u5e94\u79fb\u9664\u76d1\u542c<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">View.post(Runnable)<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u5f53\u524d layout \u6d88\u606f\u4e4b\u540e<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u53ea\u8dd1\u4e00\u6b21\uff0c\u8bed\u6cd5\u66f4\u7b80\u5355\uff0c\u4e00\u822c\u4f18\u5148\u7528\u8fd9\u4e2a<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr>\n<h2 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em; border-bottom: 2px solid #ef7060; display: flex;\"><span style=\"display: inline-block; font-weight: bold; background: #ef7060; color: #ffffff; padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;\">\u4e8c\u3001\u83b7\u53d6\u63a7\u4ef6\u5c3a\u5bf8<\/span><\/h2>\n<h3 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em;\">\u65b9\u6cd5\u4e00\uff1aOnPreDrawListener<\/h3>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">View layout = findViewById(R.id.popwindow_btn);\nViewTreeObserver vto = layout.getViewTreeObserver();\nvto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {\n    public boolean onPreDraw() {\n        if (hasMeasured == false) {\n            int btWidth = layout.getMeasuredWidth();\n            int btHeight = layout.getMeasuredHeight();\n            hasMeasured = true;\n        }\n        return true;\n    }\n});<\/code><\/pre>\n<h3 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em;\">\u65b9\u6cd5\u4e8c\uff1aOnGlobalLayoutListener<\/h3>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">ViewTreeObserver vto = mPopupBtn.getViewTreeObserver();\nvto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {\n    @Override\n    public void onGlobalLayout() {\n        if (hasMeasured == false) {\n            int btWidth = mPopupBtn.getMeasuredWidth();\n            int btHeight = mPopupBtn.getMeasuredHeight();\n            hasMeasured = true;\n        }\n    }\n});<\/code><\/pre>\n<h3 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em;\">\u65b9\u6cd5\u4e09\uff1aView.post()<\/h3>\n<p style=\"margin: 1em 0px;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">setContentView()<\/code> \u4e4b\u540e\uff0cUI \u4e8b\u4ef6\u961f\u5217\u91cc\u4f1a\u6709\u4e00\u6761\u8981\u6c42\u91cd\u65b0 layout \u7684\u6d88\u606f\u3002\u4f60 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">post<\/code> \u8fdb\u53bb\u7684 Runnable \u4f1a\u6392\u5728\u5b83\u540e\u9762\uff0c\u56e0\u6b64 run \u65f6\u5bbd\u9ad8\u5df2\u7ecf\u5c31\u7eea\u3002\u6bd4 Observer \u7701\u4e8b\uff1a\u53ea\u6267\u884c\u4e00\u6b21\uff0c\u4e5f\u4e0d\u7528\u518d\u7981\u7528\u76d1\u542c\u3002<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">final View view = \/\/ smth;\nview.post(new Runnable() {\n    @Override\n    public void run() {\n        view.getHeight(); \/\/ height is ready\n    }\n});<\/code><\/pre>\n<hr>\n<h2 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em; border-bottom: 2px solid #ef7060; display: flex;\"><span style=\"display: inline-block; font-weight: bold; background: #ef7060; color: #ffffff; padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;\">\u4e09\u3001\u72b6\u6001\u680f\u3001\u6807\u9898\u680f\u3001\u5c4f\u5e55\u4e0e\u5185\u5bb9\u533a<\/span><\/h2>\n<p style=\"margin: 1em 0px;\">\u72b6\u6001\u680f\u9ad8\u5ea6\u53d6\u53ef\u89c1\u7a97\u53e3\u77e9\u5f62\u7684 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">frame.top<\/code>\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">public int getStatusBarHeight() {\n    Rect frame = new Rect();\n    getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);\n    int statusBarHeight = frame.top;\n    return statusBarHeight;\n}<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u6807\u9898\u680f\uff1a\u5185\u5bb9\u533a\u9876\u90e8\u51cf\u53bb\u72b6\u6001\u680f\uff1b\u6709 ActionBar \u65f6\u4e5f\u53ef\u76f4\u63a5 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">getActionBar().getHeight()<\/code>\uff08\u9700\u786e\u8ba4 Title \/ ActionBar \u6ca1\u6709\u9690\u85cf\uff09\u3002<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">public int getTitleBarHeight() {\n    int statusBarHeight = getStatusBarHeight();\n    int contentTop = getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();\n    int titleBarHeight = contentTop - statusBarHeight;\n    return titleBarHeight;\n}\n\npublic int getTitleBarHeight() {\n    return getActionBar().getHeight();\n}<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u5c4f\u5e55\u5bbd\u9ad8\u7528 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">DisplayMetrics<\/code>\uff1b\u5185\u5bb9\u533a\u9ad8\u5ea6\u8d70 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">android.R.id.content<\/code>\u3002<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">public int[] getScreenSize() {\n    DisplayMetrics dm = new DisplayMetrics();\n    getWindowManager().getDefaultDisplay().getMetrics(dm);\n    int screenWidth = dm.widthPixels;\n    int screenHeigh = dm.heightPixels;\n    return new int[] { screenWidth, screenHeigh };\n}\n\nint contentViewHeight = findViewById(android.R.id.content).getHeight();<\/code><\/pre>\n<hr>\n<h2 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em; border-bottom: 2px solid #ef7060; display: flex;\"><span style=\"display: inline-block; font-weight: bold; background: #ef7060; color: #ffffff; padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;\">\u56db\u3001\u5f39\u6846\u5b9e\u4f8b<\/span><\/h2>\n<p style=\"margin: 1em 0px;\">\u5f39\u7a97\u5bbd = \u5c4f\u5e55\u5bbd\u51cf\u4e24\u4fa7\u8fb9\u8ddd\uff1b\u9ad8 = \u5185\u5bb9\u533a\u9ad8\u5ea6\u51cf\u6309\u94ae\u9ad8\u5ea6\u518d\u51cf\u8fb9\u8ddd\u3002\u70b9\u51fb\u7a7a\u767d\u5173\u95ed\u9700\u8bbe\u80cc\u666f\u3001\u53ef\u805a\u7126\u3001\u5916\u90e8\u53ef\u70b9\u3002\u5b9a\u4f4d\u7528 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">getLocationOnScreen<\/code>\uff0c<code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">location[0]<\/code> \u662f x\uff0c<code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">location[1]<\/code> \u662f y\u3002<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">public void showPopupWindow(int buttonHeight) {\n    View contentView = getPopWindowContentViewBySimpleAdatper();\n    int margin = 50;\n    int contentViewHeight = findViewById(android.R.id.content).getHeight();\n    int[] screenSize = getScreenSize();\n    int screenWidth = screenSize[0];\n    int screenHeigh = screenSize[1];\n    int titleHeight = getTitleBarHeight();\n    int statusBarHeight = getStatusBarHeight();\n    int popwindowWidth = screenWidth - 2 * margin;\n    int popwindowHeight = contentViewHeight - buttonHeight - margin;\n    \/\/ int popwindowHeight = screenHeigh - buttonHeight - titleHeight - statusBarHeight - margin;\n\n    mPopwindow = new PopupWindow(contentView, popwindowWidth, popwindowHeight);\n    mPopwindow.setBackgroundDrawable(new BitmapDrawable());\n    mPopwindow.setFocusable(true);\n    mPopwindow.setOutsideTouchable(true);\n\n    mPopupBtn.setOnClickListener(new OnClickListener() {\n        @Override\n        public void onClick(View v) {\n            if (mPopwindow.isShowing()) {\n                mPopwindow.dismiss();\n            } else {\n                int[] location = new int[2];\n                v.getLocationOnScreen(location);\n                Logs.v(\"location[0] :\" + location[0] + \" location[1] :\" + location[1]);\n                mPopwindow.showAtLocation(v, Gravity.NO_GRAVITY, location[0] + 50, location[1] + v.getHeight());\n            }\n        }\n    });\n}<\/code><\/pre>\n<blockquote style=\"margin: 20px 0px; display: block; font-size: 0.9em; overflow: auto; border-left: 3px solid #ef7060; color: #6a737d; padding: 10px 10px 10px 20px; background: #fff9f9;\">\n<p style=\"margin: 1em 0px;\"><strong>\u4e00\u53e5\u8bdd\u603b\u7ed3\uff1aonCreate \u91cf\u4e0d\u5230\u5bbd\u9ad8\uff0c\u7b49 layout \u5b8c\u6210\u518d\u7528 View.post \u6216 ViewTreeObserver\uff1b\u5c4f\u5e55\u3001\u72b6\u6001\u680f\u3001\u6807\u9898\u680f\u3001\u5185\u5bb9\u533a\u5206\u5f00\u53d6\uff0c\u5f39\u7a97\u5bbd\u9ad8\u624d\u80fd\u7b97\u5bf9\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 Android \u91cc\u91cf\u63a7\u4ef6\u5bbd\u9ad8\uff0conCreate \u91cc\u76f4\u63a5 getHeight() \/ getMeasured [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[195],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/813"}],"collection":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=813"}],"version-history":[{"count":3,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/813\/revisions"}],"predecessor-version":[{"id":3222,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/813\/revisions\/3222"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=813"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=813"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}