{"id":476,"date":"2015-04-20T19:31:52","date_gmt":"2015-04-20T11:31:52","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=476"},"modified":"2026-08-18T12:58:40","modified_gmt":"2026-08-18T04:58:40","slug":"%e5%8d%95%e4%bd%8d%e5%92%8c%e5%b0%ba%e5%af%b8","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=476","title":{"rendered":"\u5355\u4f4d\u548c\u5c3a\u5bf8"},"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;\">\u4e3a\u4e86\u9002\u914d\u4e0d\u540c\u5c4f\u5e55\uff0c\u6307\u5b9a\u63a7\u4ef6\u548c\u5e03\u5c40\u5927\u5c0f\u65f6\u6700\u597d\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;\">match_parent<\/code> \u548c <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;\">wrap_content<\/code>\uff0c\u5c3d\u91cf\u522b\u5199\u6b7b\u5bbd\u9ad8\u3002\u771f\u8981\u56fa\u5b9a\u503c\u65f6\uff0c\u5e03\u5c40\u91cc\u5e38\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;\">px<\/code>\u3001<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;\">pt<\/code>\u3001<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;\">dp<\/code>\u3001<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;\">sp<\/code>\u3002\u524d\u4e24\u4e2a\u5728\u624b\u673a\u4e0a\u5f88\u5bb9\u6613\u300c\u4e00\u5757\u5c4f\u4e00\u4e2a\u6837\u300d\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\u3001px \u548c pt\uff1aPC \u597d\u7528\uff0c\u624b\u673a\u5403\u529b<\/span><\/h2>\n<p style=\"margin: 1em 0px;\"><strong>px<\/strong> \u662f\u50cf\u7d20\uff0c\u5c4f\u5e55\u80fd\u663e\u793a\u7684\u6700\u5c0f\u5355\u5143\u3002\u5355\u4e2a\u50cf\u7d20\u8089\u773c\u51e0\u4e4e\u770b\u4e0d\u89c1\uff0c\u805a\u5728\u4e00\u8d77\u624d\u7ec4\u6210\u754c\u9762\u3002<strong>pt<\/strong> \u662f\u78c5\uff0c1 \u78c5 = 1\/72 \u82f1\u5bf8\uff0c\u5e38\u5f53\u5b57\u4f53\u5355\u4f4d\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u5728 PC \u4e0a\u7528 px \/ pt \u5f88\u987a\u624b\uff1b\u5230\u624b\u673a\u4e0a\u5206\u8fa8\u7387\u4e94\u82b1\u516b\u95e8\uff1a200px \u5bbd\u7684\u6309\u94ae\u5728\u4f4e\u5206\u5c4f\u53ef\u80fd\u8fd1\u4e4e\u6ee1\u5c4f\uff0c\u9ad8\u5206\u5c4f\u53ef\u80fd\u53ea\u5360\u4e00\u534a\u3002\u628a <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;\">activity_main.xml<\/code> \u6539\u6210\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;\">&lt;LinearLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\" &gt;\n  &lt;Button\n    android:id=\"@+id\/button\"\n    android:layout_width=\"200px\"\n    android:layout_height=\"wrap_content\"\n    android:text=\"Button\"\n  \/&gt;\n&lt;\/LinearLayout&gt;<\/code><\/pre>\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;\">android:layout_width<\/code> \u5199\u6210 200px \u540e\uff0c\u518d\u5728 240\u00d7320 \u7684\u4f4e\u5206\u8fa8\u7387\u6a21\u62df\u5668\u4e0a\u8dd1\u4e00\u904d\uff0c\u540c\u6837 200px \u7684\u89c2\u611f\u5b8c\u5168\u4e0d\u540c\u3002pt \u548c px \u60c5\u51b5\u7c7b\u4f3c\uff0c\u6240\u4ee5\u8fd9\u4e24\u4e2a\u5355\u4f4d\u5728\u624b\u673a\u4e0a\u5f88\u96be\u5f53\u9ed8\u8ba4\u5c3a\u5bf8\u3002<\/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;\">\u4e8c\u3001dp \u548c sp\uff1a\u8ddf\u5bc6\u5ea6\u8d70<\/span><\/h2>\n<p style=\"margin: 1em 0px;\">Google \u4e3a\u6b64\u5f15\u5165 <strong>dp<\/strong>\uff08density-independent pixel\uff0c\u4e5f\u53eb dip\uff09\u548c <strong>sp<\/strong>\uff08scale-independent pixel\uff09\u3002dp \u5728\u4e0d\u540c\u5bc6\u5ea6\u5c4f\u5e55\u4e0a\u663e\u793a\u6bd4\u4f8b\u66f4\u4e00\u81f4\uff1bsp \u7528\u540c\u4e00\u5957\u601d\u8def\u89e3\u51b3\u6587\u5b57\u5927\u5c0f\uff0c\u5e76\u4f1a\u968f\u7528\u6237\u5b57\u4f53\u7f29\u653e\u3002<\/p>\n<p style=\"margin: 1em 0px;\"><strong>\u5bc6\u5ea6<\/strong>\u662f\u6bcf\u82f1\u5bf8\u50cf\u7d20\u6570\uff0c\u5355\u4f4d dpi\u3002\u5c4f\u5e55\u5bbd 2 \u82f1\u5bf8\u3001\u957f 3 \u82f1\u5bf8\uff1a\u5206\u8fa8\u7387 320\u00d7480 \u65f6\u5bc6\u5ea6\u7ea6 160dpi\uff1b640\u00d7960 \u65f6\u7ea6 320dpi\u3002\u5bc6\u5ea6\u8d8a\u9ad8\uff0c\u753b\u9762\u8d8a\u7cbe\u7ec6\u3002\u53ef\u5728 <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\u6253\u5370\u5f53\u524d\u5bc6\u5ea6\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 class MainActivity extends Activity {\n  @Override\n  protected void onCreate(Bundle savedInstanceState) {\n    super.onCreate(savedInstanceState);\n    setContentView(R.layout.activity_main);\n    float xdpi = getResources().getDisplayMetrics().xdpi;\n    float ydpi = getResources().getDisplayMetrics().ydpi;\n    Log.d(\"MainActivity\", \"xdpi is \" + xdpi);\n    Log.d(\"MainActivity\", \"ydpi is \" + ydpi);\n  }\n}<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u6309 Android \u7ea6\u5b9a\uff1a160dpi \u4e0a 1dp = 1px\uff0c320dpi \u4e0a 1dp = 2px\u3002\u7528 dp \u6307\u5b9a\u5bbd\u9ad8\uff0c\u63a7\u4ef6\u5728\u4e0d\u540c\u5bc6\u5ea6\u4e0a\u7684\u89c6\u89c9\u6bd4\u4f8b\u624d\u80fd\u7a33\u4f4f\u3002\u628a\u6309\u94ae\u5bbd\u5ea6\u6539\u6210 200dp\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;\">&lt;LinearLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\" &gt;\n  &lt;Button\n    android:id=\"@+id\/button\"\n    android:layout_width=\"200dp\"\n    android:layout_height=\"wrap_content\"\n    android:text=\"Button\"\n  \/&gt;\n&lt;\/LinearLayout&gt;<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u82e5\u6a21\u62df\u5668\u521a\u597d\u662f 160dpi\uff0c\u8fd9\u65f6 1dp = 1px\uff0c\u770b\u8d77\u6765\u4f1a\u548c 200px \u51e0\u4e4e\u4e00\u6837\uff1b\u6362\u5230\u4f4e\u5bc6\u5ea6\u6a21\u62df\u5668\uff0cdp \u7684\u4f18\u52bf\u624d\u4f1a\u660e\u663e\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;\">\u5355\u4f4d<\/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;\">\u542b\u4e49<\/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;\">\u624b\u673a\u4e0a\u600e\u4e48\u7528<\/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;\">px<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u7269\u7406\u50cf\u7d20<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u5c11\u5199\u6b7b\uff1b\u540c px \u5728\u4e0d\u540c\u5206\u8fa8\u7387\u4e0a\u5360\u6bd4\u5dee\u5f88\u5927<\/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;\">pt<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u78c5\uff0c1\/72 \u82f1\u5bf8<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u4f20\u7edf\u5b57\u4f53\u5355\u4f4d\uff0c\u624b\u673a\u9002\u914d\u540c\u6837\u5403\u529b<\/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;\">dp \/ dip<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u5bc6\u5ea6\u65e0\u5173\u50cf\u7d20<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u63a7\u4ef6\u5bbd\u9ad8\u9996\u9009\uff1b160dpi \u65f6 1dp=1px<\/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;\">sp<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u53ef\u4f38\u7f29\u50cf\u7d20<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u6587\u5b57\u5927\u5c0f\u9996\u9009\uff0c\u53ef\u8ddf\u7cfb\u7edf\u5b57\u4f53\u7f29\u653e<\/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;\">\u4e09\u3001\u6362\u7b97\u5173\u7cfb<\/span><\/h2>\n<p style=\"margin: 1em 0px;\">\u66f4\u7ec6\u7684 px \u2194 dp \u6362\u7b97\u53ef\u4ee5\u770b\uff1a<a href=\"http:\/\/johnsonxu.iteye.com\/blog\/1929027\">Android Dimension \u8f6c\u6362\u7b97\u6cd5\u539f\u7406\u5206\u6790<\/a>\u3002\u65e5\u5e38\u8bb0\u5fc6\uff1a\u4f18\u5148 <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;\">match_parent<\/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;\">wrap_content<\/code>\uff1b\u975e\u5199\u56fa\u5b9a\u503c\u4e0d\u53ef\u65f6\uff0c\u63a7\u4ef6\u7528 dp\uff0c\u5b57\u53f7\u7528 sp\u3002<\/p>\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\uff1apx\/pt \u8ddf\u7269\u7406\u50cf\u7d20\u7ed1\u6b7b\uff0c\u6362\u5206\u8fa8\u7387\u5c31\u53d8\u5f62\uff1b\u63a7\u4ef6\u7528 dp\u3001\u6587\u5b57\u7528 sp\uff0c\u624d\u80fd\u5728\u4e0d\u540c\u5bc6\u5ea6\u4e0a\u4fdd\u6301\u5dee\u4e0d\u591a\u7684\u89c6\u89c9\u5927\u5c0f\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>\u4e3a\u4e86\u9002\u914d\u4e0d\u540c\u5c4f\u5e55\uff0c\u6307\u5b9a\u63a7\u4ef6\u548c\u5e03\u5c40\u5927\u5c0f\u65f6\u6700\u597d\u7528 match_parent \u548c wrap_content\uff0c\u5c3d\u91cf\u522b\u5199 [&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\/476"}],"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=476"}],"version-history":[{"count":3,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/476\/revisions"}],"predecessor-version":[{"id":881,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/476\/revisions\/881"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=476"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=476"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=476"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}