{"id":442,"date":"2025-12-04T16:27:13","date_gmt":"2025-12-04T08:27:13","guid":{"rendered":"https:\/\/www.52runoob.com\/?p=442"},"modified":"2025-12-04T16:27:13","modified_gmt":"2025-12-04T08:27:13","slug":"android-layout%e5%b8%83%e5%b1%80_androidlayout","status":"publish","type":"post","link":"https:\/\/www.52runoob.com\/index.php\/2025\/12\/04\/android-layout%e5%b8%83%e5%b1%80_androidlayout\/","title":{"rendered":"Android Layout\u5e03\u5c40_android:layout"},"content":{"rendered":"\n<p>\u4e0b\u9762\u7ed9\u4f60\u6574\u7406\u4e00\u7bc7 <strong>Android Layout \u5e03\u5c40\u8be6\u89e3\u6307\u5357<\/strong>\uff0c\u4ece\u57fa\u7840\u5c5e\u6027\u5230\u5e38\u7528\u5e03\u5c40\u7c7b\u578b\uff0c\u4fbf\u4e8e\u521d\u5b66\u8005\u7406\u89e3 <code>android:layout_*<\/code> \u7cfb\u5217\u5c5e\u6027\u53ca\u5e03\u5c40\u539f\u7406\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>Android Layout \u5e03\u5c40\u8be6\u89e3\uff08android:layout \u7cfb\u5217\u5c5e\u6027\u6307\u5357\uff09<\/strong><\/h1>\n\n\n\n<p>\u5728 Android \u5f00\u53d1\u4e2d\uff0c\u5e03\u5c40\uff08Layout\uff09\u51b3\u5b9a\u4e86\u63a7\u4ef6\uff08View\uff09\u5728\u5c4f\u5e55\u4e0a\u7684\u6392\u5217\u65b9\u5f0f\u3002\u7406\u89e3 <code>android:layout<\/code> \u7cfb\u5217\u5c5e\u6027\u662f\u5b9e\u73b0 UI \u8bbe\u8ba1\u7684\u57fa\u7840\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e00\u3001Layout \u7684\u57fa\u7840\u6982\u5ff5<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Layout\uff08\u5e03\u5c40\uff09<\/strong>\uff1a\u51b3\u5b9a\u63a7\u4ef6\u5982\u4f55\u6392\u5217\u548c\u663e\u793a<\/li>\n\n\n\n<li><strong>ViewGroup<\/strong>\uff1a\u6240\u6709\u5e03\u5c40\u7684\u7236\u7c7b<\/li>\n\n\n\n<li><strong>View<\/strong>\uff1a\u5b50\u63a7\u4ef6\uff0c\u4f8b\u5982 Button\u3001TextView<\/li>\n\n\n\n<li><strong>android:layout_<\/strong>*\uff1a\u63a7\u4ef6\u5728\u7236\u5e03\u5c40\u4e2d\u7684\u4f4d\u7f6e\u3001\u5927\u5c0f\u548c\u6392\u5217\u65b9\u5f0f<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u5e38\u7528 Layout \u5c5e\u6027<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u5c5e\u6027<\/th><th>\u8bf4\u660e<\/th><\/tr><\/thead><tbody><tr><td><code>android:layout_width<\/code><\/td><td>\u63a7\u4ef6\u5bbd\u5ea6\uff0c\u53ef\u7528\u503c\uff1a<code>match_parent<\/code> \/ <code>wrap_content<\/code> \/ \u56fa\u5b9a\u5c3a\u5bf8\uff08\u5982 200dp\uff09<\/td><\/tr><tr><td><code>android:layout_height<\/code><\/td><td>\u63a7\u4ef6\u9ad8\u5ea6\uff0c\u540c\u4e0a<\/td><\/tr><tr><td><code>android:layout_margin<\/code><\/td><td>\u63a7\u4ef6\u5916\u8fb9\u8ddd\uff0c\u5355\u4f4d dp<\/td><\/tr><tr><td><code>android:layout_marginTop\/Bottom\/Left\/Right<\/code><\/td><td>\u5355\u72ec\u8bbe\u7f6e\u4e0a\u4e0b\u5de6\u53f3\u8fb9\u8ddd<\/td><\/tr><tr><td><code>android:layout_padding<\/code><\/td><td>\u63a7\u4ef6\u5185\u8fb9\u8ddd\uff08View \u5185\u90e8\u5185\u5bb9\u8ddd\u79bb\u8fb9\u754c\u8ddd\u79bb\uff09<\/td><\/tr><tr><td><code>android:layout_gravity<\/code><\/td><td>\u63a7\u4ef6\u5728\u7236\u5e03\u5c40\u4e2d\u7684\u5bf9\u9f50\u65b9\u5f0f\uff08LinearLayout\u3001FrameLayout\uff09<\/td><\/tr><tr><td><code>android:gravity<\/code><\/td><td>\u63a7\u4ef6\u5185\u90e8\u5185\u5bb9\u7684\u5bf9\u9f50\u65b9\u5f0f\uff08TextView\u3001Button \u5185\u6587\u5b57\u7b49\uff09<\/td><\/tr><tr><td><code>android:layout_weight<\/code><\/td><td>LinearLayout \u4e2d\u63a7\u4ef6\u5360\u6bd4\u6743\u91cd<\/td><\/tr><tr><td><code>android:layout_alignParentTop\/Bottom\/Left\/Right<\/code><\/td><td>RelativeLayout \u4e2d\u63a7\u4ef6\u76f8\u5bf9\u7236\u5e03\u5c40\u5bf9\u9f50<\/td><\/tr><tr><td><code>android:layout_centerInParent<\/code><\/td><td>RelativeLayout \u4e2d\u63a7\u4ef6\u5c45\u4e2d<\/td><\/tr><tr><td><code>android:layout_above\/below<\/code><\/td><td>RelativeLayout \u4e2d\u63a7\u4ef6\u76f8\u5bf9\u5176\u4ed6\u63a7\u4ef6\u7684\u4f4d\u7f6e<\/td><\/tr><tr><td><code>android:layout_toLeftOf\/toRightOf<\/code><\/td><td>RelativeLayout \u4e2d\u63a7\u4ef6\u76f8\u5bf9\u5176\u4ed6\u63a7\u4ef6\u5de6\u53f3\u6392\u5217<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e8c\u3001\u5e38\u7528\u5e03\u5c40\u7c7b\u578b<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. LinearLayout\uff08\u7ebf\u6027\u5e03\u5c40\uff09<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7279\u70b9<\/strong>\uff1a\u63a7\u4ef6\u6309\u5782\u76f4\uff08vertical\uff09\u6216\u6c34\u5e73\uff08horizontal\uff09\u6392\u5217<\/li>\n\n\n\n<li><strong>\u5e38\u7528\u5c5e\u6027<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li><code>android:orientation=\"vertical|horizontal\"<\/code><\/li>\n\n\n\n<li><code>android:layout_weight<\/code>\uff1a\u6309\u6bd4\u4f8b\u5206\u914d\u5269\u4f59\u7a7a\u95f4<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p>\u793a\u4f8b\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;LinearLayout\n    android:layout_width=&quot;match_parent&quot;\n    android:layout_height=&quot;wrap_content&quot;\n    android:orientation=&quot;vertical&quot;&gt;\n\n    &amp;lt;Button\n        android:layout_width=&quot;match_parent&quot;\n        android:layout_height=&quot;0dp&quot;\n        android:layout_weight=&quot;1&quot;\n        android:text=&quot;Button 1&quot;\/&gt;\n    \n    &amp;lt;Button\n        android:layout_width=&quot;match_parent&quot;\n        android:layout_height=&quot;0dp&quot;\n        android:layout_weight=&quot;2&quot;\n        android:text=&quot;Button 2&quot;\/&gt;\n&amp;lt;\/LinearLayout&gt;\n\n<\/pre><\/div>\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Button 1 \u5360 1\/3\uff0cButton 2 \u5360 2\/3 \u9ad8\u5ea6<\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. RelativeLayout\uff08\u76f8\u5bf9\u5e03\u5c40\uff09<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7279\u70b9<\/strong>\uff1a\u63a7\u4ef6\u53ef\u76f8\u5bf9\u7236\u5e03\u5c40\u6216\u5176\u4ed6\u63a7\u4ef6\u5b9a\u4f4d<\/li>\n\n\n\n<li><strong>\u5e38\u7528\u5c5e\u6027<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li><code>layout_alignParentTop\/Bottom\/Left\/Right<\/code><\/li>\n\n\n\n<li><code>layout_centerInParent<\/code><\/li>\n\n\n\n<li><code>layout_below\/above\/toLeftOf\/toRightOf<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p>\u793a\u4f8b\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;RelativeLayout\n    android:layout_width=&quot;match_parent&quot;\n    android:layout_height=&quot;wrap_content&quot;&gt;\n\n    &amp;lt;TextView\n        android:id=&quot;@+id\/title&quot;\n        android:layout_width=&quot;wrap_content&quot;\n        android:layout_height=&quot;wrap_content&quot;\n        android:text=&quot;Title&quot;\n        android:layout_centerHorizontal=&quot;true&quot;\/&gt;\n\n    &amp;lt;Button\n        android:layout_width=&quot;wrap_content&quot;\n        android:layout_height=&quot;wrap_content&quot;\n        android:text=&quot;Next&quot;\n        android:layout_below=&quot;@id\/title&quot;\n        android:layout_alignParentRight=&quot;true&quot;\/&gt;\n&amp;lt;\/RelativeLayout&gt;\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. FrameLayout\uff08\u5e27\u5e03\u5c40\uff09<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7279\u70b9<\/strong>\uff1a\u63a7\u4ef6\u5806\u53e0\u663e\u793a\uff0c\u5e38\u7528\u4e8e\u8986\u76d6\u5c42\u6216\u7b80\u5355\u5e03\u5c40<\/li>\n\n\n\n<li><strong>\u5e38\u7528\u5c5e\u6027<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li><code>android:layout_gravity<\/code> \u63a7\u4ef6\u5bf9\u9f50\u65b9\u5f0f<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p>\u793a\u4f8b\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;FrameLayout\n    android:layout_width=&quot;match_parent&quot;\n    android:layout_height=&quot;200dp&quot;&gt;\n\n    &amp;lt;ImageView\n        android:layout_width=&quot;match_parent&quot;\n        android:layout_height=&quot;match_parent&quot;\n        android:src=&quot;@drawable\/bg&quot;\/&gt;\n\n    &amp;lt;TextView\n        android:layout_width=&quot;wrap_content&quot;\n        android:layout_height=&quot;wrap_content&quot;\n        android:text=&quot;Hello&quot;\n        android:layout_gravity=&quot;center&quot;\/&gt;\n&amp;lt;\/FrameLayout&gt;\n\n<\/pre><\/div>\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>TextView \u5c45\u4e2d\u663e\u793a\u5728 ImageView \u4e0a<\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. TableLayout\uff08\u8868\u683c\u5e03\u5c40\uff09<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7279\u70b9<\/strong>\uff1a\u5c06\u63a7\u4ef6\u6309\u884c\u5217\u6392\u5217<\/li>\n\n\n\n<li><strong>\u5e38\u7528\u5b50\u63a7\u4ef6<\/strong>\uff1a<code>TableRow<\/code><\/li>\n<\/ul>\n\n\n\n<p>\u793a\u4f8b\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;TableLayout\n    android:layout_width=&quot;match_parent&quot;\n    android:layout_height=&quot;wrap_content&quot;&gt;\n\n    &amp;lt;TableRow&gt;\n        &amp;lt;TextView android:text=&quot;Name&quot;\/&gt;\n        &amp;lt;EditText android:layout_width=&quot;wrap_content&quot;\/&gt;\n    &amp;lt;\/TableRow&gt;\n\n    &amp;lt;TableRow&gt;\n        &amp;lt;TextView android:text=&quot;Age&quot;\/&gt;\n        &amp;lt;EditText android:layout_width=&quot;wrap_content&quot;\/&gt;\n    &amp;lt;\/TableRow&gt;\n\n&amp;lt;\/TableLayout&gt;\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5. GridLayout\uff08\u7f51\u683c\u5e03\u5c40\uff0cAPI 14+\uff09<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7279\u70b9<\/strong>\uff1a\u63a7\u4ef6\u6309\u884c\u5217\u6392\u5217\uff0c\u53ef\u81ea\u5b9a\u4e49\u884c\u5217\u5360\u6bd4<\/li>\n\n\n\n<li><strong>\u5e38\u7528\u5c5e\u6027<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li><code>android:layout_row<\/code><\/li>\n\n\n\n<li><code>android:layout_column<\/code><\/li>\n\n\n\n<li><code>android:layout_rowSpan<\/code> \/ <code>layout_columnSpan<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e09\u3001\u5e03\u5c40\u4f18\u5316\u5efa\u8bae<\/strong><\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u5c3d\u91cf\u5c11\u5d4c\u5957<\/strong>\uff1a\u8fc7\u591a\u5d4c\u5957\u4f1a\u5f71\u54cd\u6027\u80fd<\/li>\n\n\n\n<li><strong>\u4f7f\u7528 <code>weight<\/code> \u5206\u914d\u7a7a\u95f4<\/strong>\uff1aLinearLayout \u4e2d\u4f7f\u7528 <code>layout_weight<\/code> \u4ee3\u66ff\u56fa\u5b9a\u5c3a\u5bf8\uff0c\u9002\u914d\u6027\u66f4\u597d<\/li>\n\n\n\n<li><strong>RelativeLayout \u4f18\u5148\u5bf9\u9f50\u800c\u975e\u5d4c\u5957<\/strong><\/li>\n\n\n\n<li><strong>ConstraintLayout\uff08\u63a8\u8350\uff09<\/strong>\uff1aAndroid Studio \u73b0\u5728\u63a8\u8350\u4f7f\u7528 ConstraintLayout\uff0c\u5b9e\u73b0\u66f4\u590d\u6742\u5e03\u5c40\u800c\u51cf\u5c11\u5c42\u7ea7<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u56db\u3001\u603b\u7ed3<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>LinearLayout<\/strong>\uff1a\u7ebf\u6027\u6392\u5217\uff0c\u7b80\u5355\u660e\u4e86<\/li>\n\n\n\n<li><strong>RelativeLayout<\/strong>\uff1a\u76f8\u5bf9\u5b9a\u4f4d\uff0c\u7075\u6d3b<\/li>\n\n\n\n<li><strong>FrameLayout<\/strong>\uff1a\u5806\u53e0\u63a7\u4ef6\uff0c\u8986\u76d6\u663e\u793a<\/li>\n\n\n\n<li><strong>TableLayout\/GridLayout<\/strong>\uff1a\u8868\u683c\/\u7f51\u683c\u6392\u5217<\/li>\n\n\n\n<li><strong>\u5e03\u5c40\u4f18\u5316<\/strong>\uff1a\u5c11\u5d4c\u5957\u3001\u4f7f\u7528\u6743\u91cd\u3001ConstraintLayout<\/li>\n<\/ul>\n\n\n\n<p>\u638c\u63e1 <code>android:layout_*<\/code> \u7cfb\u5217\u5c5e\u6027\uff0c\u662f Android UI \u5f00\u53d1\u7684\u57fa\u7840\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0b\u9762\u7ed9\u4f60\u6574\u7406\u4e00\u7bc7 Android Layout \u5e03\u5c40\u8be6\u89e3\u6307\u5357\uff0c\u4ece\u57fa\u7840\u5c5e\u6027\u5230\u5e38\u7528\u5e03&#8230; <a class=\"more-link\" href=\"https:\/\/www.52runoob.com\/index.php\/2025\/12\/04\/android-layout%e5%b8%83%e5%b1%80_androidlayout\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-442","post","type-post","status-publish","format-standard","hentry","category-12"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/442","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/comments?post=442"}],"version-history":[{"count":1,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/442\/revisions"}],"predecessor-version":[{"id":443,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/442\/revisions\/443"}],"wp:attachment":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/media?parent=442"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/categories?post=442"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/tags?post=442"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}