{"id":499,"date":"2015-04-20T20:31:18","date_gmt":"2015-04-20T12:31:18","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=499"},"modified":"2026-08-15T16:46:44","modified_gmt":"2026-08-15T08:46:44","slug":"%e6%ac%a2%e8%bf%8e%e5%bc%80%e5%a7%8bandroid%e5%ba%94%e7%94%a8%e5%bc%80%e5%8f%91%e4%b9%8b%e6%97%85%ef%bc%81","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=499","title":{"rendered":"\u6b22\u8fce\u5f00\u59cbAndroid\u5e94\u7528\u5f00\u53d1\u4e4b\u65c5\uff01"},"content":{"rendered":"<p><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2024\/05\/image.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-3498\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2024\/05\/image.png\" alt=\"\" width=\"2151\" height=\"1105\" srcset=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2024\/05\/image.png 2151w, https:\/\/ai.zhousir.top\/wp-content\/uploads\/2024\/05\/image-768x395.png 768w, https:\/\/ai.zhousir.top\/wp-content\/uploads\/2024\/05\/image-1536x789.png 1536w, https:\/\/ai.zhousir.top\/wp-content\/uploads\/2024\/05\/image-2048x1052.png 2048w\" sizes=\"(max-width: 2151px) 100vw, 2151px\" \/><\/a><\/p>\n<p>\u672c\u7ae0\u8282\u6559\u4f60\u5982\u4f55\u5efa\u7acb\u4f60\u7684\u7b2c\u4e00\u4e2aAndroid\u5e94\u7528\u7a0b\u5e8f\u3002\u60a8\u5c06\u5b66\u5230\u5982\u4f55\u521b\u5efa\u4e00\u4e2aAndroid\u9879\u76ee\u548c\u8fd0\u884c\u53ef\u8c03\u8bd5\u7248\u672c\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\u4f60\u8fd8\u5c06\u5b66\u4e60\u5230\u4e00\u4e9bAndroid\u5e94\u7528\u7a0b\u5e8f\u8bbe\u8ba1\u7684\u57fa\u7840\u77e5\u8bc6\uff0c\u5305\u62ec\u5982\u4f55\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u7528\u6237\u754c\u9762\uff0c\u4ee5\u53ca\u5904\u7406\u7528\u6237\u8f93\u5165\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u5f00\u59cb\u672c\u7ae0\u8282\u5b66\u4e60\u4e4b\u524d\uff0c\u786e\u4fdd\u4f60\u5df2\u7ecf<\/p>\n<p>1.<a href=\"https:\/\/ai.zhousir.top\/?p=446\">\u4e86\u89e3Android\u5e73\u53f0<\/a><\/p>\n<p>2.<a href=\"https:\/\/ai.zhousir.top\/?p=9\">\u5b89\u88c5\u4e86\u5f00\u53d1\u73af\u5883<\/a><\/p>\n<p>3.<a href=\"https:\/\/ai.zhousir.top\/?p=436\">\u6491\u63e1Android\u9879\u76ee\u7ed3\u6784<\/a><\/p>\n<p>4.<a href=\"https:\/\/ai.zhousir.top\/?p=442\">Android\u56fe\u578b\u7528\u6237\u754c\u9762\u76f8\u5173\u77e5\u8bc6<\/a><\/p>\n<h2 id=\"linearlayout\">\u521b\u5efa\u4e00\u4e2aLinearLayout<\/h2>\n<p>1 \u521b\u5efaAndroid\u65b0\u9879\u76ee\uff0c\u4eceres\/layout\u76ee\u5f55\u6253\u5f00activity_my.xml\u6587\u4ef6\u3002\u4fee\u6539\u5e03\u5c40\u6587\u4ef6.<\/p>\n<p>\u4fee\u6539\u540e\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n<p>res\/layout\/activity_my.xml<\/p>\n<pre><code>&lt;LinearLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    android:orientation=\"horizontal\" &gt;\n&lt;\/LinearLayout&gt;\n<\/code><\/pre>\n<p><a href=\"http:\/\/developer.android.com\/reference\/android\/widget\/LinearLayout.html\" target=\"_blank\" rel=\"noopener\">LinearLayout<\/a>\u662f<a href=\"http:\/\/developer.android.com\/reference\/android\/view\/ViewGroup.html\" target=\"_blank\" rel=\"noopener\">ViewGroup<\/a>\u7684\u4e00\u4e2a\u5b50\u7c7b\uff0c\u7528\u4e8e\u653e\u7f6e\u6c34\u5e73\u6216\u8005\u5782\u76f4\u653e\u7f6e\u5b50\u89c6\u56fe\u7684\u90e8\u4ef6\uff0c\u7531\u5c5e\u6027<code>android:orientation<\/code>\u6765\u8bbe\u5b9a\u65b9\u5411\u3002LinearLayout\u91cc\u7684\u5b50\u5e03\u5c40\u6309\u7167XML\u91cc\u5b9a\u4e49\u7684\u987a\u5e8f\u5411\u663e\u793a\u5728\u5c4f\u5e55\u4e0a\u3002<\/p>\n<p>\u53e6\u5916\u7684\u4e24\u4e2a\u5c5e\u6027<a href=\"http:\/\/developer.android.com\/reference\/android\/view\/View.html#attr_android:layout_width\" target=\"_blank\" rel=\"noopener\">android:layout_width<\/a>\u548c<a href=\"http:\/\/developer.android.com\/reference\/android\/view\/View.html#attr_android:layout_height\" target=\"_blank\" rel=\"noopener\">android:layout_height<\/a>\uff0c\u5bf9\u4e8e\u6240\u6709\u7684Views\u90fd\u9700\u8981\u5bf9\u8fd9\u4e24\u4e2a\u5c5e\u6027\u8fdb\u884c\u8bbe\u7f6e\u6765\u6307\u5b9a\u5c3a\u5bf8\u3002<\/p>\n<p>\u5728\u8fd9\u91cc\u56e0\u4e3aLinearLayout\u662f\u6574\u4e2a\u89c6\u56fe\u7684\u6839\u5e03\u5c40\uff0c\u6240\u4ee5\u5bf9\u4e8e\u5bbd\u548c\u9ad8\u90fd\u5e94\u8be5\u662f\u5145\u6ee1\u6574\u4e2a\u5c4f\u5e55\u7684\uff0c\u901a\u8fc7\u6307\u5b9awidth \u548c height\u5c5e\u6027\u4e3a<code>\"match_parent\"<\/code>\u3002\u8be5\u503c\u8868\u793a\u5b50View\u6269\u5f20\u81ea\u5df1width\u548cheight\u6765\u5339\u914d\u7236\u63a7\u4ef6\u7684width\u548cheight\u3002<\/p>\n<p>\u60f3\u8981\u83b7\u5f97\u66f4\u591a\u5173\u4e8e<a href=\"http:\/\/developer.android.com\/guide\/topics\/ui\/declaring-layout.html\" target=\"_blank\" rel=\"noopener\">Layout<\/a>\u5c5e\u6027\u7684\u4fe1\u606f\uff0c\u8bf7\u53c2\u7167XML\u5e03\u5c40\u5411\u5bfc\u3002<\/p>\n<h2 id=\"\">\u6dfb\u52a0\u4e00\u4e2a\u6587\u672c\u8f93\u5165\u6846<\/h2>\n<p>\u4e0e\u5176\u5b83View\u4e00\u6837\uff0c\u4f60\u9700\u8981\u8bbe\u7f6eXML\u91cc\u7684\u67d0\u4e9b\u5c5e\u6027\u6765\u6307\u5b9aEditText\u7684\u5c5e\u6027\u503c\uff0c\u4e0b\u8fb9\u662f\u4f60\u5e94\u8be5\u5728\u7ebf\u6027\u5e03\u5c40\u91cc\u6307\u5b9a\u7684\u4e00\u4e9b\u5c5e\u6027\u5143\u7d20\uff1a<\/p>\n<p>1 \u5728activity_my.xml \u6587\u4ef6\u7684 \u6807\u7b7e\u5185\u5b9a\u4e49\u4e00\u4e2a \u6807\u7b7e\uff0c\u5e76\u8bbe\u7f6eid\u4e3a@+id\/edit_message.<\/p>\n<p>2 \u8bbe\u7f6elayout_width\u548clayout_height\u5c5e\u6027\u4e3a wrap_content.<\/p>\n<p>3 \u8bbe\u7f6ehint\u5c5e\u6027\u4e3a\u4e00\u4e2astring \u503c\u7684\u5f15\u7528edit_message.<\/p>\n<p>res\/layout\/activity_my.xml<\/p>\n<pre><code>&lt;EditText android:id=\"@+id\/edit_message\"\n    android:layout_width=\"wrap_content\"\n    android:layout_height=\"wrap_content\"\n    android:hint=\"@string\/edit_message\" \/&gt;\n<\/code><\/pre>\n<p>\u5c5e\u6027\u8bf4\u660e:<\/p>\n<h4 id=\"androididhttpdeveloperandroidcomreferenceandroidviewviewhtmlattr_androidid\"><a href=\"http:\/\/developer.android.com\/reference\/android\/view\/View.html#attr_android:id\" target=\"_blank\" rel=\"noopener\">android:id<\/a><\/h4>\n<p>\u8fd9\u91cc\u5b9a\u4e49\u7684\u662fView\u7684\u552f\u4e00\u6807\u793a\u7b26\uff0c\u4f60\u53ef\u4ee5\u5728\u7a0b\u5e8f\u7684\u4ee3\u7801\u91cc\u8fdb\u884c\u5f15\u7528\uff0c\u4f60\u53ef\u4ee5\u5bf9\u8fd9\u4e2a\u7c7b\u8fdb\u884c\u8bfb\u548c\u4fee\u6539\u7684\u64cd\u4f5c(\u5728\u4e0b\u4e00\u8bfe\u91cc\u5c06\u4f1a\u7528\u5230)<\/p>\n<p>\u5f53\u4f60\u60f3\u4eceXML\u91cc\u4f7f\u7528\u8d44\u6e90\u7c7b\u7684\u65f6\u5019\u5fc5\u987b\u4f7f\u7528@\u7b26\u53f7\uff0c\u7d27\u968f<code>@<\/code>\u4e4b\u540e\u7684\u662f\u8d44\u6e90\u7684\u7c7b\u578b(\u8fd9\u91cc\u662f<code>id<\/code>)\uff0c\u7136\u540e\u662f\u8d44\u6e90\u7684\u540d\u5b57(\u8fd9\u91cc\u4f7f\u7528\u7684\u662f<code>edit_message<\/code>)\u3002(\u5176\u4ed6\u7684\u8d44\u6e90\u53ef\u4ee5\u4f7f\u7528\u76f8\u540c\u7684\u540d\u5b57\u53ea\u8981\u4ed6\u4eec\u4e0d\u662f\u76f8\u540c\u7684\u8d44\u6e90\u7c7b\u578b\uff0c\u4f8b\u5982\uff1a\u5b57\u7b26\u4e32\u8d44\u6e90\u53ef\u4ee5\u4f7f\u7528\u76f8\u540c\u7684\u540d\u5b57)\u3002<\/p>\n<p>+\u53f7\u53ea\u662f\u5f53\u4f60\u7b2c\u4e00\u6b21\u5b9a\u4e49\u4e00\u4e2a\u8d44\u6e90ID\u7684\u65f6\u5019\u9700\u8981\u3002\u8fd9\u91cc\u662f\u544a\u8bc9SDK\u6b64\u8d44\u6e90ID\u9700\u8981\u88ab\u521b\u5efa\u51fa\u6765\u3002\u5728\u5e94\u7528\u7a0b\u5e8f\u88ab\u7f16\u8bd1\u4e4b\u540e\uff0cSDK\u5c31\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528ID\u503c\uff0cedit_message\u662f\u5728\u9879\u76ee<code>gen\/R.java<\/code>\u6587\u4ef6\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6807\u793a\u7b26\uff0c\u8fd9\u4e2a\u6807\u793a\u7b26\u5c31\u548c<a href=\"http:\/\/developer.android.com\/reference\/android\/widget\/EditText.html\" target=\"_blank\" rel=\"noopener\">EditText<\/a>\u5173\u8054\u8d77\u6765\u4e86\u3002\u4e00\u65e6\u8d44\u6e90ID\u88ab\u521b\u5efa\u4e86\uff0c\u5176\u4ed6\u8d44\u6e90\u5982\u679c\u5f15\u7528\u8fd9\u4e2aID\u5c31\u4e0d\u518d\u9700\u8981+\u53f7\u4e86\u3002\u8fd9\u91cc\u662f\u552f\u4e00\u4e00\u4e2a\u9700\u8981+\u53f7\u7684\u5c5e\u6027\u3002<\/p>\n<h4 id=\"androidlayout_widthhttpdeveloperandroidcomreferenceandroidviewviewhtmlattr_androidlayout_width-androidlayout_heighthttpdeveloperandroidcomreferenceandroidviewviewhtmlattr_androidlayout_height\"><a href=\"http:\/\/developer.android.com\/reference\/android\/view\/View.html#attr_android:layout_width\" target=\"_blank\" rel=\"noopener\">android:layout_width<\/a> \u548c<a href=\"http:\/\/developer.android.com\/reference\/android\/view\/View.html#attr_android:layout_height\" target=\"_blank\" rel=\"noopener\">android:layout_height<\/a><\/h4>\n<p>\u5bf9\u4e8e\u5bbd\u548c\u9ad8\u4e0d\u5efa\u8bae\u6307\u5b9a\u5177\u4f53\u7684\u5927\u5c0f\uff0c\u4f7f\u7528<code>wrap_content<\/code>\u6307\u5b9a\u4e4b\u540e\uff0c\u8fd9\u4e2a\u89c6\u56fe\u53ea\u662f\u5360\u636e\u5185\u5bb9\u5927\u5c0f\u7684\u7a7a\u95f4\u3002\u5982\u679c\u4f60\u4f7f\u7528\u4e86<code>match_parent<\/code>\uff0c\u8fd9\u65f6<a href=\"http:\/\/developer.android.com\/reference\/android\/widget\/EditText.html\" target=\"_blank\" rel=\"noopener\">EditText<\/a>\u5c06\u4f1a\u5e03\u6ee1\u6574\u4e2a\u5c4f\u5e55\uff0c\u56e0\u4e3a\u5b83\u5c06\u9002\u5e94\u7236\u5e03\u5c40\u7684\u5927\u5c0f\u3002\u60f3\u8981\u770b\u5230\u66f4\u591a\u4fe1\u606f\uff0c\u8bf7\u53c2\u8003 <a href=\"http:\/\/developer.android.com\/guide\/topics\/ui\/declaring-layout.html\" target=\"_blank\" rel=\"noopener\">\u5e03\u5c40\u5411\u5bfc<\/a>\u3002<\/p>\n<h4 id=\"androidhinthttpdeveloperandroidcomreferenceandroidwidgettextviewhtmlattr_androidhint\"><a href=\"http:\/\/developer.android.com\/reference\/android\/widget\/TextView.html#attr_android:hint\" target=\"_blank\" rel=\"noopener\">android:hint<\/a><\/h4>\n<p>\u5f53\u6587\u672c\u6846\u4e3a\u7a7a\u7684\u65f6\u5019,\u4f1a\u9ed8\u8ba4\u663e\u793a\u8fd9\u4e2a\u5b57\u7b26\u4e32\u3002\u5bf9\u4e8e\u5b57\u7b26\u4e32<code>@string\/edit_message<\/code>\u7684\u503c\u6240\u5f15\u7528\u7684\u8d44\u6e90\u5e94\u8be5\u662f\u5b9a\u4e49\u5728\u5355\u72ec\u7684\u6587\u4ef6\u91cc\uff0c\u800c\u4e0d\u662f\u76f4\u63a5\u4f7f\u7528\u5b57\u7b26\u4e32\u3002\u56e0\u4e3a\u4f7f\u7528\u7684\u662f\u503c\u662f\u5b58\u5728\u7684\u8d44\u6e90\uff0c\u6240\u4ee5\u4e0d\u9700\u8981\u4f7f\u7528+\u53f7\u3002\u7136\u800c\uff0c\u7531\u4e8e\u4f60\u8fd8\u6ca1\u6709\u5b9a\u4e49\u5b57\u7b26\u4e32\u7684\u503c\uff0c\u6240\u4ee5\u5728\u6dfb\u52a0<code>@string\/edit_message<\/code>\u65f6\u5019\u4f1a\u51fa\u73b0\u7f16\u8bd1\u9519\u8bef\u3002\u4e0b\u8fb9\u4f60\u53ef\u4ee5\u5b9a\u4e49\u5b57\u7b26\u4e32\u8d44\u6e90\u503c\u6765\u53bb\u9664\u8fd9\u4e2a\u9519\u8bef\u3002<\/p>\n<blockquote><p><strong>Note<\/strong>: \u8be5\u5b57\u7b26\u4e32\u8d44\u6e90\u4e0eid\u4f7f\u7528\u4e86\u76f8\u540c\u7684\u540d\u79f0\uff08edit_message\uff09\u3002\u7136\u800c\uff0c\u5bf9\u4e8e\u8d44\u6e90\u7684\u5f15\u7528\u662f\u533a\u5206\u7c7b\u578b\u7684\uff08\u6bd4\u5982id\u548c\u5b57\u7b26\u4e32\uff09\uff0c\u56e0\u6b64\uff0c\u4f7f\u7528\u76f8\u540c\u7684\u540d\u79f0\u4e0d\u4f1a\u5f15\u8d77\u51b2\u7a81\u3002<\/p><\/blockquote>\n<h2 id=\"\">\u589e\u52a0\u5b57\u7b26\u4e32\u8d44\u6e90<\/h2>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u4f60\u7684Android\u9879\u76ee\u5305\u542b\u4e00\u4e2a\u5b57\u7b26\u4e32\u8d44\u6e90\u6587\u4ef6\uff0c<code>res\/values\/string.xml<\/code>\u3002\u6253\u5f00\u8fd9\u4e2a\u6587\u4ef6\uff0c\u4e3a<code>\"edit_message\"<\/code>\u589e\u52a0\u4e00\u4e2a\u4f9b\u4f7f\u7528\u7684\u5b57\u7b26\u4e32\u5b9a\u4e49\uff0c\u8bbe\u7f6e\u503c\u4e3a&#8221;Enter a message.&#8221;<\/p>\n<p>1 \u5728Android Studio, f\u4eceres\/values \u6253\u5f00strings.xml.<\/p>\n<p>2 \u6dfb\u52a0\u4e00\u4e2astring\u540d\u4e3a&#8221;edit_message&#8221; ,\u503c\u4e3a &#8220;Enter a message&#8221;.<\/p>\n<p>3 \u518d\u6dfb\u52a0\u4e00\u4e2astring\u540d\u4e3a &#8220;button_send&#8221;\uff0c\u503c\u4e3a&#8221;Send&#8221;.<\/p>\n<p>4 \u63a5\u4e0b\u6765\u5c06\u4f7f\u7528\u7b2c3\u6b65\u521b\u5efa\u7684string.<\/p>\n<p>5 \u5220\u9664 &#8220;hello world&#8221; string.<\/p>\n<p>\u4e0b\u8fb9\u5c31\u662f\u5b9a\u4e49\u597d\u7684<code>res\/values\/strings.xml<\/code>\u6587\u4ef6\u5185\u5bb9\uff1a<\/p>\n<pre><code>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&lt;resources&gt;\n    &lt;string name=\"app_name\"&gt;My First App&lt;\/string&gt;\n    &lt;string name=\"edit_message\"&gt;Enter a message&lt;\/string&gt;\n    &lt;string name=\"button_send\"&gt;Send&lt;\/string&gt;\n    &lt;string name=\"action_settings\"&gt;Settings&lt;\/string&gt;\n    &lt;string name=\"title_activity_main\"&gt;MainActivity&lt;\/string&gt;\n&lt;\/resources&gt;\n<\/code><\/pre>\n<p>\u5f53\u4f60\u5728\u7528\u6237\u754c\u9762\u5b9a\u4e49\u4e00\u4e2a\u6587\u672c\u7684\u65f6\u5019\uff0c\u4f60\u5e94\u8be5\u628a\u6bcf\u4e00\u4e2a\u6587\u672c\u5b57\u7b26\u4e32\u5217\u5165\u8d44\u6e90\u6587\u4ef6\u3002\u5bf9\u4e8e\u6240\u6709\u5b57\u7b26\u4e32\u503c\uff0c\u5b57\u7b26\u4e32\u8d44\u6e90\u80fd\u591f\u5355\u72ec\u7684\u4fee\u6539\uff0c\u5728\u8d44\u6e90\u6587\u4ef6\u91cc\u4f60\u53ef\u4ee5\u5f88\u5bb9\u6613\u7684\u627e\u5230\u5e76\u4e14\u505a\u51fa\u76f8\u5e94\u7684\u4fee\u6539\u3002\u901a\u8fc7\u9009\u62e9\u5b9a\u4e49\u6bcf\u4e2a\u5b57\u7b26\u4e32\uff0c\u8fd8\u5141\u8bb8\u60a8\u5bf9\u4e0d\u540c\u8bed\u8a00\u672c\u5730\u5316\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>\u8981\u60f3\u83b7\u5f97\u8ddf\u591a\u7684\u5bf9\u4e8e\u4e0d\u540c\u8bed\u8a00\u672c\u5b57\u7b26\u4e32\u8d44\u6e90\u672c\u5730\u5316\u7684\u95ee\u9898\uff0c\u8bf7\u53c2\u8003<a href=\"http:\/\/hukai.me\/android-training-course-in-chinese\/basics\/supporting-devices\/index.html\">\u517c\u5bb9\u4e0d\u540c\u7684\u8bbe\u5907(Supporting Different Devices)<\/a> \u3002<\/p>\n<h2 id=\"\">\u6dfb\u52a0\u4e00\u4e2a\u6309\u94ae<\/h2>\n<p>1 \u5728 Android Studio\u91cc, \u7f16\u8f91 res\/layout\u4e0b\u7684 activity_my.xml \u6587\u4ef6.<\/p>\n<p>2 \u5728LinearLayout \u5185\u90e8, \u5b9a\u4e49\u4e00\u4e2aButton&gt;\u6807\u7b7e\u7d27\u63a5\u7740 EditText\u6807\u7b7e.<\/p>\n<p>3 \u8bbe\u7f6eButton\u7684width \u548c height \u5c5e\u6027\u503c\u4e3a &#8220;wrap_content&#8221; \u4ee5\u4fbf\u8ba9Button\u5927\u5c0f\u80fd\u5b8c\u6574\u663e\u793a\u5176\u4e0a\u7684\u6587\u672c.<\/p>\n<p>4 \u5b9a\u4e49button\u7684\u6587\u672c\u4f7f\u7528android:text \u5c5e\u6027\uff0c\u8bbe\u7f6e\u5176\u503c\u4e3a\u524d\u8fb9\u5b9a\u4e49\u597d\u7684 button_send \u5b57\u7b26\u4e32.<\/p>\n<p>\u6b64\u65f6\u7684 LinearLayout \u770b\u8d77\u6765\u5e94\u8be5\u662f\u8fd9\u6837<\/p>\n<p>res\/layout\/activity_my.xml<\/p>\n<pre><code>&lt;LinearLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    android:orientation=\"horizontal\" &gt;\n      &lt;EditText android:id=\"@+id\/edit_message\"\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:hint=\"@string\/edit_message\" \/&gt;\n      &lt;Button\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:text=\"@string\/button_send\" \/&gt;\n&lt;\/LinearLayout&gt;\n<\/code><\/pre>\n<p><strong>Note<\/strong> \u5bbd\u548c\u9ad8\u88ab\u8bbe\u7f6e\u4e3a<code>\"wrap_content\"<\/code>\uff0c\u8fd9\u65f6\u6309\u94ae\u5360\u636e\u7684\u5927\u5c0f\u5c31\u662f\u6309\u94ae\u91cc\u6587\u672c\u7684\u5927\u5c0f\u3002\u8fd9\u4e2a\u6309\u94ae\u4e0d\u9700\u8981\u6307\u5b9a<a href=\"http:\/\/developer.android.com\/reference\/android\/view\/View.html#attr_android:id\" target=\"_blank\" rel=\"noopener\">android:id<\/a>\u7684\u5c5e\u6027\uff0c\u56e0\u4e3a\u5728<span class=\"glossary-term\" title=\"An activity represents a single screen with a user interface.\" data-glossary-term=\"activity\">Activity<\/span>\u4ee3\u7801\u91cc\u4e0d\u88ab\u5f15\u7528\u5230\u3002<\/p>\n<p>\u5f53\u524dEditText\u548cButton\u90e8\u4ef6\u53ea\u662f\u9002\u5e94\u4e86\u4ed6\u4eec\u5404\u81ea\u5185\u5bb9\u7684\u5927\u5c0f\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p>\u8fd9\u6837\u8bbe\u7f6e\u5bf9\u6309\u94ae\u6765\u8bf4\u5f88\u5408\u9002\uff0c\u4f46\u662f\u5bf9\u4e8e\u6587\u672c\u6846\u6765\u8bf4\u5c31\u4e0d\u592a\u597d\u4e86\uff0c\u56e0\u4e3a\u7528\u6237\u53ef\u80fd\u8f93\u5165\u66f4\u957f\u7684\u6587\u672c\u5185\u5bb9\u3002\u56e0\u6b64\u5982\u679c\u80fd\u591f\u5360\u6ee1\u6574\u4e2a\u5c4f\u5e55\u5bbd\u5ea6\u4f1a\u66f4\u597d\u3002LinearLayout\u4f7f\u7528\u6743\u91cd\u7684\u5c5e\u6027\u6765\u8fbe\u5230\u8fd9\u4e2a\u76ee\u7684\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<a href=\"http:\/\/developer.android.com\/reference\/android\/widget\/LinearLayout.LayoutParams.html#weight\" target=\"_blank\" rel=\"noopener\">android:layout_weight<\/a>\u5c5e\u6027\u6765\u8bbe\u7f6e\u3002<\/p>\n<p>\u4f60\u53ef\u4ee5\u6839\u636e\u6bcf\u4e00\u4e2a\u90e8\u4ef6\u6240\u5360\u7684\u7a7a\u95f4\u6765\u6307\u5b9a\u6743\u91cd\u503c\u7684\u5927\u5c0f\uff0c\u5b83\u7684\u603b\u6570\u662f\u6709\u540c\u7ea7\u522b\u7684\u90e8\u4ef6\u6765\u51b3\u5b9a\u7684\u3002\u5c31\u7c7b\u4f3c\u4e8e\u996e\u6599\u7684\u6210\u5206\u914d\u65b9\uff1a\u201c\u4e24\u4efd\u4f0f\u7279\u52a0\u9152\uff0c\u4e00\u4efd\u5496\u5561\u5229\u53e3\u9152\u201d\uff0c\u610f\u601d\u5c31\u662f\u8fd9\u4e2a\u9152\u4e2d\u4f0f\u7279\u52a0\u9152\u5360\u4e09\u5206\u4e4b\u4e8c\u3002\u4f8b\u5982\uff0c\u4f60\u8bbe\u7f6e\u4e00\u4e2aView\u7684\u6743\u91cd\u662f2\uff0c\u53e6\u4e00\u4e2aView\u7684\u6743\u91cd\u662f1\uff0c\u90a3\u4e48\u603b\u6570\u5c31\u662f3\uff0c\u8fd9\u65f6\u7b2c\u4e00\u4e2aView\u5360\u636e2\/3\u7684\u7a7a\u95f4\uff0c\u7b2c\u4e8c\u4e2a\u5360\u636e1\/3\u7684\u7a7a\u95f4\u3002\u5982\u679c\u4f60\u518d\u52a0\u5165\u7b2c\u4e09\u4e2aView\uff0c\u6743\u91cd\u8bbe\u4e3a1\uff0c\u90a3\u4e48\u7b2c\u4e00\u4e2aView(\u6743\u91cd\u4e3a2\u7684)\u4f1a\u5360\u636e1\/2\u7684\u7a7a\u95f4\uff0c\u5269\u4f59\u7684\u53e6\u5916\u4e24\u4e2aView\u5404\u53601\/4\u3002(\u8bf7\u6ce8\u610f\uff0c\u4f7f\u7528\u6743\u91cd\u7684\u524d\u63d0\u4e00\u822c\u662f\u7ed9View\u7684\u5bbd\u6216\u8005\u9ad8\u7684\u5927\u5c0f\u8bbe\u7f6e\u4e3a0dp\uff0c\u7136\u540e\u7cfb\u7edf\u6839\u636e\u4e0a\u9762\u7684\u6743\u91cd\u89c4\u5219\u6765\u8ba1\u7b97View\u5e94\u8be5\u5360\u636e\u7684\u7a7a\u95f4\u3002\u4f46\u662f\u5f88\u591a\u60c5\u51b5\u4e0b\uff0c\u5982\u679c\u7ed9View\u8bbe\u7f6e\u4e86match_parent\u7684\u5c5e\u6027\uff0c\u90a3\u4e48\u4e0a\u9762\u8ba1\u7b97\u6743\u91cd\u65f6\u5219\u4e0d\u662f\u901a\u5e38\u7684\u6b63\u6bd4\uff0c\u800c\u662f\u53cd\u6bd4\uff0c\u4e5f\u5c31\u662f\u6743\u91cd\u503c\u5927\u7684\u53cd\u800c\u5360\u636e\u7a7a\u95f4\u5c0f)\u3002<\/p>\n<p>\u5bf9\u4e8e\u6240\u6709\u7684View\u9ed8\u8ba4\u7684\u6743\u91cd\u662f0\uff0c\u5982\u679c\u4f60\u53ea\u8bbe\u7f6e\u4e86\u4e00\u4e2aView\u7684\u6743\u91cd\u5927\u4e8e0\uff0c\u90a3\u4e48\u8fd9\u4e2aView\u5c06\u5360\u636e\u9664\u53bb\u522b\u7684View\u672c\u8eab\u5360\u636e\u7684\u7a7a\u95f4\u7684\u6240\u6709\u5269\u4f59\u7a7a\u95f4\u3002\u56e0\u6b64\u8fd9\u91cc\u8bbe\u7f6eEditText\u7684\u6743\u91cd\u4e3a1\uff0c\u4f7f\u5176\u80fd\u591f\u5360\u636e\u9664\u4e86\u6309\u94ae\u4e4b\u5916\u7684\u6240\u6709\u7a7a\u95f4\u3002<\/p>\n<h2 id=\"\">\u8ba9\u8f93\u5165\u6846\u5145\u6ee1\u6574\u4e2a\u5c4f\u5e55\u7684\u5bbd\u5ea6<\/h2>\n<p>\u4e3a\u8ba9 EditText\u5145\u6ee1\u5269\u4f59\u7a7a\u95f4\uff0c\u505a\u5982\u4e0b\u64cd\u4f5c\uff1a<\/p>\n<p>1 \u5728activity_my.xml\u6587\u4ef6\u91cc\uff0c\u8bbe\u7f6eEditText\u7684layout_weight\u5c5e\u6027\u503c\u4e3a1 .<\/p>\n<p>2 \u540c\u65f6\u8bbe\u7f6eEditText\u7684layout_width\u503c\u4e3a0dp.<\/p>\n<p>res\/layout\/activity_my.xml<\/p>\n<pre><code>&lt;EditText\n    android:layout_weight=\"1\"\n    android:layout_width=\"0dp\"\n    ... \/&gt;\n<\/code><\/pre>\n<p>\u4e3a\u4e86\u63d0\u5347\u5e03\u5c40\u7684\u6548\u7387\uff0c\u5728\u8bbe\u7f6e\u6743\u91cd\u7684\u65f6\u5019\uff0c\u4f60\u5e94\u8be5\u628a<a href=\"http:\/\/developer.android.com\/reference\/android\/widget\/EditText.html\" target=\"_blank\" rel=\"noopener\">EditText<\/a>\u7684\u5bbd\u5ea6\u8bbe\u7f6e\u4e3a0dp\u3002\u5982\u679c\u4f60\u8bbe\u7f6e\u4e3a&#8221;wrap_content&#8221;\u4f5c\u4e3a\u5bbd\u5ea6\uff0c\u7cfb\u7edf\u9700\u8981\u81ea\u5df1\u53bb\u8ba1\u7b97\u8fd9\u4e2a\u90e8\u4ef6\u6240\u5360\u6709\u7684\u5bbd\u5ea6\uff0c\u800c\u6b64\u65f6\u7684\u56e0\u4e3a\u4f60\u8bbe\u7f6e\u4e86\u6743\u91cd\uff0c\u6240\u4ee5\u7cfb\u7edf\u81ea\u52a8\u4f1a\u5360\u636e\u5269\u4f59\u7a7a\u95f4\uff0cEditText\u7684\u5bbd\u5ea6\u6700\u7ec8\u6210\u4e86\u4e0d\u8d77\u4f5c\u7528\u7684\u5c5e\u6027\u3002<\/p>\n<p>\u4e0b\u56fe\u5c55\u793a\u4e86\u8bbe\u7f6e\u6743\u91cd\u540e\u7684\u7684\u6548\u679c<\/p>\n<p>\u73b0\u5728\u770b\u4e00\u4e0b\u5b8c\u6574\u7684\u5e03\u5c40\u6587\u4ef6\u5185\u5bb9\uff1a<\/p>\n<p>res\/layout\/activity_my.xml<\/p>\n<pre><code>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&lt;LinearLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    android:orientation=\"horizontal\"&gt;\n    &lt;EditText android:id=\"@+id\/edit_message\"\n        android:layout_weight=\"1\"\n        android:layout_width=\"0dp\"\n        android:layout_height=\"wrap_content\"\n        android:hint=\"@string\/edit_message\" \/&gt;\n    &lt;Button\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:text=\"@string\/button_send\" \/&gt;\n&lt;\/LinearLayout&gt;\n<\/code><\/pre>\n<h2 id=\"\">\u8fd0\u884c\u5e94\u7528<\/h2>\n<p>\u6574\u4e2a\u5e03\u5c40\u9ed8\u8ba4\u88ab\u5e94\u7528\u4e8e\u521b\u5efa\u9879\u76ee\u7684\u65f6\u5019SDK\u5de5\u5177\u81ea\u52a8\u751f\u6210\u7684<span class=\"glossary-term\" title=\"An activity represents a single screen with a user interface.\" data-glossary-term=\"activity\">Activity<\/span>\uff0c\u8fd0\u884c\u770b\u4e0b\u6548\u679c:<\/p>\n<ul>\n<li>\u5728Android Studio\u91cc\uff0c\u70b9\u51fb\u5de5\u5177\u680f\u91cc\u7684Run\u6309\u94ae<img decoding=\"async\" src=\"http:\/\/hukai.me\/android-training-course-in-chinese\/basics\/firstapp\/eclipse-run.png\" alt=\"\" \/><\/li>\n<li>\u6216\u8005\u4f7f\u7528\u547d\u4ee4\u884c\uff0c\u8fdb\u5165\u4f60\u9879\u76ee\u7684\u6839\u76ee\u5f55\u76f4\u63a5\u6267\u884c<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u7ae0\u8282\u6559\u4f60\u5982\u4f55\u5efa\u7acb\u4f60\u7684\u7b2c\u4e00\u4e2aAndroid\u5e94\u7528\u7a0b\u5e8f\u3002\u60a8\u5c06\u5b66\u5230\u5982\u4f55\u521b\u5efa\u4e00\u4e2aAndroid\u9879\u76ee\u548c\u8fd0\u884c\u53ef\u8c03\u8bd5\u7248\u672c\u7684\u5e94 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[52],"tags":[],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/499"}],"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=499"}],"version-history":[{"count":7,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/499\/revisions"}],"predecessor-version":[{"id":3538,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/499\/revisions\/3538"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=499"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}