{"id":476,"date":"2015-04-20T19:31:52","date_gmt":"2015-04-20T11:31:52","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=476"},"modified":"2015-07-10T14:00:01","modified_gmt":"2015-07-10T06:00:01","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":"<p>\u524d\u9762\u6211\u4eec\u8bf4\u8fc7\uff0c\u4e3a\u4e86\u8981\u8ba9\u7a0b\u5e8f\u62e5\u6709\u66f4\u597d\u7684\u5c4f\u5e55\u9002\u914d\u80fd\u529b\uff0c\u5728\u6307\u5b9a\u63a7\u4ef6\u548c\u5e03\u5c40\u5927\u5c0f\u7684\u65f6\u5019<br \/>\n\u6700\u597d\u4f7f\u7528match_parent \u548cwrap_content\uff0c\u5c3d\u91cf\u907f\u514d\u5c06\u63a7\u4ef6\u7684\u5bbd\u548c\u9ad8\u8bbe\u5b9a\u4e00\u4e2a\u56fa\u5b9a\u503c\u3002\u4e0d\u8fc7\u5728\u6709\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4ec5\u4ec5\u4f7f\u7528match_parent \u548cwrap_content \u786e\u5b9e\u65e0\u6cd5\u6ee1\u8db3\u6211\u4eec\u7684\u9700\u6c42\uff0c\u8fd9\u65f6\u5c31\u5fc5\u987b\u8981\u7ed9\u63a7\u4ef6\u7684\u5bbd\u6216\u9ad8\u6307\u5b9a\u4e00\u4e2a\u56fa\u5b9a\u503c\u3002\u5728\u5e03\u5c40\u6587\u4ef6\u4e2d\u6307\u5b9a\u5bbd\u9ad8\u7684\u56fa\u5b9a\u5927\u5c0f\u6709\u4ee5\u4e0b\u5e38\u7528\u5355\u4f4d\u53ef\u4f9b\u9009\u62e9\uff1apx\u3001pt\u3001dp \u548csp\u3002<br \/>\n<!--more--><\/p>\n<p>px \u548cpt<\/p>\n<p>px \u662f\u50cf\u7d20\u7684\u610f\u601d\uff0c\u5373\u5c4f\u5e55\u4e2d\u53ef\u4ee5\u663e\u793a\u7684\u6700\u5c0f\u5143\u7d20\u5355\u5143\uff0c\u6211\u4eec\u5e94\u7528\u91cc\u4efb\u4f55\u53ef\u89c1\u7684\u4e1c\u897f\u90fd\u662f\u7531\u4e00\u4e2a\u4e2a\u50cf\u7d20\u70b9\u7ec4\u6210\u7684\u3002\u5355\u72ec\u4e00\u4e2a\u50cf\u7d20\u70b9\u975e\u5e38\u7684\u5fae\u5c0f\uff0c\u8089\u773c\u662f\u65e0\u6cd5\u770b\u89c1\u7684\uff0c\u53ef\u662f\u5f53\u8bb8\u8bb8\u591a\u591a\u7684\u50cf\u7d20\u70b9\u805a\u96c6\u5230\u4e00\u8d77\u65f6\uff0c\u5c31\u53ef\u4ee5\u62fc\u63a5\u6210\u4e94\u5f69\u7f24\u7eb7\u7684\u56fe\u6848\u3002<\/p>\n<p>pt \u662f\u78c5\u6570\u7684\u610f\u601d\uff0c1 \u78c5\u7b49\u4e8e1\/72 \u82f1\u5bf8\uff0c\u4e00\u822cpt \u90fd\u4f1a\u4f5c\u4e3a\u5b57\u4f53\u7684\u5355\u4f4d\u6765\u4f7f\u7528\u3002<br \/>\n\u8fc7\u53bb\u5728PC \u4e0a\u4f7f\u7528px \u548cpt \u7684\u65f6\u5019\u53ef\u4ee5\u8bf4\u662f\u975e\u5e38\u5f97\u5fc3\u5e94\u624b\uff0c\u80fd\u628a\u7a0b\u5e8f\u6253\u626e\u5f97\u6f02\u6f02\u4eae\u4eae\u3002<br \/>\n\u53ef\u662f\u73b0\u5728\u5230\u4e86\u624b\u673a\u4e0a\uff0c\u8fd9\u4e24\u4e2a\u5355\u4f4d\u5c31\u663e\u5f97\u6709\u4e9b\u529b\u4e0d\u4ece\u5fc3\u4e86\uff0c\u56e0\u4e3a\u624b\u673a\u7684\u5206\u8fa8\u7387\u5404\u4e0d\u76f8\u540c\uff0c\u4e00<br \/>\n\u4e2a200px \u5bbd\u7684\u6309\u94ae\u5728\u4f4e\u5206\u8fa8\u7387\u7684\u624b\u673a\u4e0a\u53ef\u80fd\u5c06\u8fd1\u5360\u636e\u6ee1\u5c4f\uff0c\u800c\u5230\u4e86\u9ad8\u5206\u8fa8\u7387\u7684\u624b\u673a\u4e0a\u53ef\u80fd\u53ea<br \/>\n\u5360\u636e\u5c4f\u5e55\u7684\u4e00\u534a\u3002\u6211\u4eec\u901a\u8fc7\u4f8b\u5b50\u6765\u76f4\u89c2\u5730\u770b\u4e00\u4e0b\uff0c\u4fee\u6539activity_main.xml \u4e2d\u7684\u4ee3\u7801\uff0c\u5982\u4e0b<br \/>\n\u6240\u793a\uff1a<\/p>\n<p>[java]&lt;LinearLayout xmlns:android=&quot;http:\/\/schemas.android.com\/apk\/res\/android&quot;<br \/>\nandroid:layout_width=&quot;match_parent&quot;<br \/>\nandroid:layout_height=&quot;match_parent&quot; &gt;<br \/>\n &lt;Button<br \/>\n  android:id=&quot;@+id\/button&quot;<br \/>\n  android:layout_width=&quot;200px&quot;<br \/>\n  android:layout_height=&quot;wrap_content&quot;<br \/>\n  android:text=&quot;Button&quot;<br \/>\n \/&gt;<br \/>\n&lt;\/LinearLayout&gt;[\/java]<\/p>\n<p>\u8fd9\u91cc\u901a\u8fc7android:layout_width \u5c5e\u6027\u5c06\u6309\u94ae\u7684\u5bbd\u6307\u5b9a\u4e3a200px\uff0c\u7136\u540e\u8fd0\u884c\u7a0b\u5e8f<\/p>\n<p>\u63a5\u7740\u521b\u5efa\u4e00\u4e2a240*320 \u50cf\u7d20\u7684\u4f4e\u5206\u8fa8\u7387\u6a21\u62df\u5668\uff0c\u5728\u8fd9\u4e2a\u6a21\u62df\u5668\u4e0a\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f<\/p>\n<p>\u53ef\u4ee5\u660e\u663e\u770b\u51fa\uff0c\u540c\u6837200px \u5bbd\u7684\u6309\u94ae\u5728\u4e0d\u540c\u5206\u8fa8\u7387\u7684\u5c4f\u5e55\u4e0a\u663e\u793a\u7684\u6548\u679c\u662f\u5b8c\u5168\u4e0d\u540c\u7684\uff0c<br \/>\npt \u7684\u60c5\u51b5\u548cpx \u5dee\u4e0d\u591a\uff0c\u8fd9\u5bfc\u81f4\u8fd9\u4e24\u4e2a\u5355\u4f4d\u5728\u624b\u673a\u9886\u57df\u4e0a\u9762\u5f88\u96be\u6709\u6240\u53d1\u6325\u3002<br \/>\ndp \u548csp<\/p>\n<p>\u8c37\u6b4c\u5f53\u7136\u4e5f\u610f\u8bc6\u5230\u4e86\u8fd9\u4e2a\u4ee4\u4eba\u5934\u75bc\u4e86\u95ee\u9898\uff0c\u4e8e\u662f\u4e3aAndroid \u5f15\u5165\u4e86\u4e00\u5957\u65b0\u7684\u5355\u4f4ddp \u548csp\u3002<br \/>\ndp \u662f\u5bc6\u5ea6\u65e0\u5173\u50cf\u7d20\u7684\u610f\u601d\uff0c\u4e5f\u88ab\u79f0\u4f5cdip\uff0c\u548cpx \u76f8\u6bd4\uff0c\u5b83\u5728\u4e0d\u540c\u5bc6\u5ea6\u7684\u5c4f\u5e55\u4e2d\u7684\u663e\u793a\u6bd4<br \/>\n\u4f8b\u5c06\u4fdd\u6301\u4e00\u81f4\u3002<\/p>\n<p>sp \u662f\u53ef\u4f38\u7f29\u50cf\u7d20\u7684\u610f\u601d\uff0c\u5b83\u91c7\u7528\u4e86\u548cdp \u540c\u6837\u7684\u8bbe\u8ba1\u7406\u5ff5\uff0c\u89e3\u51b3\u4e86\u6587\u5b57\u5927\u5c0f\u7684\u9002\u914d\u95ee\u9898\u3002<br \/>\n\u8fd9\u91cc\u6709\u4e00\u4e2a\u65b0\u540d\u8bcd\u9700\u8981\u5f15\u8d77\u6211\u4eec\u7684\u6ce8\u610f\uff0c\u4ec0\u4e48\u53eb\u5bc6\u5ea6\uff1fAndroid \u4e2d\u7684\u5bc6\u5ea6\u5c31\u662f\u5c4f\u5e55\u6bcf\u82f1<br \/>\n\u5bf8\u6240\u5305\u542b\u7684\u50cf\u7d20\u6570\uff0c\u901a\u5e38\u4ee5dpi \u4e3a\u5355\u4f4d\u3002\u6bd4\u5982\u4e00\u4e2a\u624b\u673a\u5c4f\u5e55\u7684\u5bbd\u662f2 \u82f1\u5bf8\u957f\u662f3 \u82f1\u5bf8\uff0c\u5982\u679c<br \/>\n\u5b83\u7684\u5206\u8fa8\u7387\u662f320*480 \u50cf\u7d20\uff0c\u90a3\u8fd9\u4e2a\u5c4f\u5e55\u7684\u5bc6\u5ea6\u5c31\u662f160dpi\uff0c\u5982\u679c\u5b83\u7684\u5206\u8fa8\u7387\u662f640*960\uff0c<br \/>\n\u90a3\u8fd9\u4e2a\u5c4f\u5e55\u7684\u5bc6\u5ea6\u5c31\u662f320dpi\uff0c\u56e0\u6b64\u5bc6\u5ea6\u503c\u8d8a\u9ad8\u7684\u5c4f\u5e55\u663e\u793a\u7684\u6548\u679c\u5c31\u8d8a\u7cbe\u7ec6\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7<br \/>\n\u4ee3\u7801\u6765\u5f97\u77e5\u5f53\u524d\u5c4f\u5e55\u7684\u5bc6\u5ea6\u503c\u662f\u591a\u5c11\uff0c\u4fee\u6539MainActivity \u4e2d\u7684\u4ee3\u7801\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<p>[java]public class MainActivity extends Activity {<br \/>\n @Override<br \/>\n protected void onCreate(Bundle savedInstanceState) {<br \/>\n   super.onCreate(savedInstanceState);<br \/>\n   setContentView(R.layout.activity_main);<br \/>\n   float xdpi = getResources().getDisplayMetrics().xdpi;<br \/>\n   float ydpi = getResources().getDisplayMetrics().ydpi;<br \/>\n   Log.d(&quot;MainActivity&quot;, &quot;xdpi is &quot; + xdpi);<br \/>\n   Log.d(&quot;MainActivity&quot;, &quot;ydpi is &quot; + ydpi);<br \/>\n }<br \/>\n}[\/java]<\/p>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u5728onCreate()\u65b9\u6cd5\u4e2d\u6211\u4eec\u52a8\u6001\u83b7\u53d6\u5230\u4e86\u5f53\u524d\u5c4f\u5e55\u7684\u5bc6\u5ea6\u503c\uff0c\u5e76\u6253\u5370\u51fa\u6765\uff0c\u91cd<br \/>\n\u65b0\u8fd0\u884c\u7a0b\u5e8f\uff0c<br \/>\n\u7136\u540e\u5728\u4f4e\u5206\u8fa8\u7387\u7684\u6a21\u62df\u5668\u4e0a\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\uff0c<\/p>\n<p>\u6839\u636eAndroid \u7684\u89c4\u5b9a\uff0c\u5728160dpi \u7684\u5c4f\u5e55\u4e0a\uff0c1dp \u7b49\u4e8e1px\uff0c\u800c\u5728320dpi \u7684\u5c4f\u5e55\u4e0a\uff0c1dp<br \/>\n\u5c31\u7b49\u4e8e2px\u3002\u56e0\u6b64\uff0c\u4f7f\u7528dp \u6765\u6307\u5b9a\u63a7\u4ef6\u7684\u5bbd\u548c\u9ad8\uff0c\u5c31\u53ef\u4ee5\u4fdd\u8bc1\u63a7\u4ef6\u5728\u4e0d\u540c\u5bc6\u5ea6\u7684\u5c4f\u5e55\u4e2d\u7684<br \/>\n\u663e\u793a\u6bd4\u4f8b\u4fdd\u6301\u4e00\u81f4\u3002\u4fee\u6539activity_main.xml \u4e2d\u7684\u4ee3\u7801\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<p>[java]&lt;LinearLayout xmlns:android=&quot;http:\/\/schemas.android.com\/apk\/res\/android&quot;<br \/>\nandroid:layout_width=&quot;match_parent&quot;<br \/>\nandroid:layout_height=&quot;match_parent&quot; &gt;<br \/>\n  &lt;Button<br \/>\n    android:id=&quot;@+id\/button&quot;<br \/>\n    android:layout_width=&quot;200dp&quot;<br \/>\n    android:layout_height=&quot;wrap_content&quot;<br \/>\n    android:text=&quot;Button&quot;<br \/>\n  \/&gt;<br \/>\n&lt;\/LinearLayout&gt;[\/java]<\/p>\n<p>\u8fd9\u91cc\u6211\u4eec\u5c06\u6309\u94ae\u7684\u5bbd\u5ea6\u6539\u6210\u4e86200dp\uff0c\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\uff0c\u6548\u679c\u5982\u56fe3.36 \u6240\u793a\uff1a<\/p>\n<p>\u54a6\uff1f\u600e\u4e48\u611f\u89c9\u548c\u4e4b\u524d\u7684\u5bbd\u5ea6\u6ca1\u6709\u4ec0\u4e48\u533a\u522b\u5462\uff1f\u8fd9\u662f\u56e0\u4e3a\u6211\u4eec\u6a21\u62df\u5668\u7684\u5c4f\u5e55\u5bc6\u5ea6\u521a\u597d\u662f<br \/>\n160dpi\uff0c\u8fd9\u65f6\u76841dp \u5c31\u7b49\u4e8e1px\u3002<br \/>\n\u7136\u540e\u5728\u4f4e\u5206\u8fa8\u7387\u7684\u6a21\u62df\u5668\u4e0a\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f<\/p>\n<h3><a href=\"http:\/\/johnsonxu.iteye.com\/blog\/1929027\">Android Dimension\u8f6c\u6362\u7b97\u6cd5\u539f\u7406\u5206\u6790<\/a><\/h3>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u9762\u6211\u4eec\u8bf4\u8fc7\uff0c\u4e3a\u4e86\u8981\u8ba9\u7a0b\u5e8f\u62e5\u6709\u66f4\u597d\u7684\u5c4f\u5e55\u9002\u914d\u80fd\u529b\uff0c\u5728\u6307\u5b9a\u63a7\u4ef6\u548c\u5e03\u5c40\u5927\u5c0f\u7684\u65f6\u5019 \u6700\u597d\u4f7f\u7528match_parent [&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":[],"_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":4,"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}]}}