{"id":961,"date":"2025-12-25T16:06:15","date_gmt":"2025-12-25T08:06:15","guid":{"rendered":"https:\/\/www.52runoob.com\/?p=961"},"modified":"2025-12-25T16:06:15","modified_gmt":"2025-12-25T08:06:15","slug":"android-layout%e5%b8%83%e5%b1%80_androidlayout-2","status":"publish","type":"post","link":"https:\/\/www.52runoob.com\/index.php\/2025\/12\/25\/android-layout%e5%b8%83%e5%b1%80_androidlayout-2\/","title":{"rendered":"Android Layout\u5e03\u5c40_android:layout\u00a0"},"content":{"rendered":"\n<p>\u5728 Android \u5f00\u53d1\u4e2d\uff0cUI \u754c\u9762\u662f\u901a\u8fc7 <strong>\u5e03\u5c40\uff08Layout\uff09<\/strong> \u6765\u5b9e\u73b0\u7684\uff0c\u5e03\u5c40\u51b3\u5b9a\u4e86\u63a7\u4ef6\u7684\u6392\u5217\u65b9\u5f0f\u3001\u5c3a\u5bf8\u548c\u4f4d\u7f6e\u3002<br>\u7406\u89e3\u5e03\u5c40\u4f53\u7cfb\u548c <code>android:layout_*<\/code> \u5c5e\u6027\u662f\u5199\u51fa\u9ad8\u8d28\u91cf\u754c\u9762\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\">\u4e00\u3001Android \u5e03\u5c40\u4f53\u7cfb\u6982\u89c8<\/h2>\n\n\n\n<p>Android \u5e03\u5c40\u4e3b\u8981\u5206\u4e24\u7c7b\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>ViewGroup \u5e03\u5c40\u5bb9\u5668<\/strong>\uff08\u627f\u8f7d\u5b50\u63a7\u4ef6\uff09<\/li>\n\n\n\n<li><strong>View \u63a7\u4ef6<\/strong>\uff08\u5b9e\u9645\u663e\u793a\u5185\u5bb9\uff0c\u5982 TextView\u3001Button\uff09<\/li>\n<\/ol>\n\n\n\n<p>\u5e38\u89c1\u5e03\u5c40\u5bb9\u5668\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u5e03\u5c40<\/th><th>\u7279\u70b9<\/th><th>\u793a\u4f8b<\/th><\/tr><\/thead><tbody><tr><td>LinearLayout<\/td><td>\u5b50\u63a7\u4ef6\u7ebf\u6027\u6392\u5217\uff08\u6c34\u5e73 \/ \u5782\u76f4\uff09<\/td><td><code>android:orientation=\"vertical\"<\/code><\/td><\/tr><tr><td>RelativeLayout \/ ConstraintLayout<\/td><td>\u5b50\u63a7\u4ef6\u76f8\u5bf9\u6392\u5217<\/td><td><code>app:layout_constraintTop_toTopOf<\/code><\/td><\/tr><tr><td>FrameLayout<\/td><td>\u5806\u53e0\u5e03\u5c40\uff08\u5e38\u7528\u4e8e\u8986\u76d6\u5c42\uff09<\/td><td>\u80cc\u666f + \u5f39\u7a97<\/td><\/tr><tr><td>TableLayout<\/td><td>\u8868\u683c\u5e03\u5c40<\/td><td>\u884c \/ \u5217<\/td><\/tr><tr><td>GridLayout<\/td><td>\u7f51\u683c\u5e03\u5c40<\/td><td>\u7c7b\u4f3c\u8868\u683c\uff0c\u4f46\u66f4\u7075\u6d3b<\/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\">\u4e8c\u3001<code>android:layout_*<\/code> \u5c5e\u6027\u8be6\u89e3<\/h2>\n\n\n\n<p><code>android:layout_*<\/code> \u5c5e\u6027\u7528\u4e8e<strong>\u5b9a\u4e49\u5b50\u63a7\u4ef6\u5728\u7236\u5e03\u5c40\u4e2d\u7684\u8868\u73b0<\/strong>\uff0c\u4e3b\u8981\u5305\u62ec\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u5c3a\u5bf8<\/strong><\/li>\n\n\n\n<li><strong>\u5bf9\u9f50 \/ \u4f4d\u7f6e<\/strong><\/li>\n\n\n\n<li><strong>\u6743\u91cd \/ \u6bd4\u4f8b<\/strong><\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">1\ufe0f\u20e3 \u5c3a\u5bf8\u5c5e\u6027<\/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><th>\u793a\u4f8b<\/th><\/tr><\/thead><tbody><tr><td><code>android:layout_width<\/code><\/td><td>\u63a7\u4ef6\u5bbd\u5ea6<\/td><td><code>match_parent<\/code> \/ <code>wrap_content<\/code> \/ \u5177\u4f53 dp<\/td><\/tr><tr><td><code>android:layout_height<\/code><\/td><td>\u63a7\u4ef6\u9ad8\u5ea6<\/td><td><code>match_parent<\/code> \/ <code>wrap_content<\/code> \/ \u5177\u4f53 dp<\/td><\/tr><\/tbody><\/table><\/figure>\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;TextView\n    android:layout_width=&quot;match_parent&quot;\n    android:layout_height=&quot;wrap_content&quot;\n    android:text=&quot;Hello World&quot; \/&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\">2\ufe0f\u20e3 \u4f4d\u7f6e\u4e0e\u5bf9\u9f50<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">LinearLayout<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>android:layout_gravity<\/code>\uff1a\u63a7\u4ef6\u5728\u7236\u5e03\u5c40\u4e2d\u7684\u5bf9\u9f50\u65b9\u5f0f<\/li>\n\n\n\n<li><code>android:gravity<\/code>\uff1a\u63a7\u4ef6\u5185\u90e8\u5185\u5bb9\u5bf9\u9f50\u65b9\u5f0f<\/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;200dp&quot;\n    android:orientation=&quot;vertical&quot;\n    android:gravity=&quot;center&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;\u6309\u94ae&quot;\n        android:layout_gravity=&quot;center_horizontal&quot;\/&gt;\n&amp;lt;\/LinearLayout&gt;\n\n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\">RelativeLayout<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>android:layout_alignParentTop=\"true\"<\/code><\/li>\n\n\n\n<li><code>android:layout_centerInParent=\"true\"<\/code><\/li>\n\n\n\n<li><code>android:layout_below=\"@id\/otherView\"<\/code><\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">3\ufe0f\u20e3 \u6743\u91cd \/ \u6bd4\u4f8b\uff08LinearLayout \u7279\u6709\uff09<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>android:layout_weight<\/code>\uff1a\u5206\u914d\u7236\u5bb9\u5668\u5269\u4f59\u7a7a\u95f4\u6bd4\u4f8b<\/li>\n\n\n\n<li>\u5e38\u7528\u4e8e\u54cd\u5e94\u5f0f\u5e03\u5c40<\/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;horizontal&quot;&gt;\n\n    &amp;lt;Button\n        android:layout_width=&quot;0dp&quot;\n        android:layout_height=&quot;wrap_content&quot;\n        android:layout_weight=&quot;1&quot;\n        android:text=&quot;\u6309\u94ae1&quot;\/&gt;\n\n    &amp;lt;Button\n        android:layout_width=&quot;0dp&quot;\n        android:layout_height=&quot;wrap_content&quot;\n        android:layout_weight=&quot;2&quot;\n        android:text=&quot;\u6309\u94ae2&quot;\/&gt;\n&amp;lt;\/LinearLayout&gt;\n\n<\/pre><\/div>\n\n\n<p>\u8bf4\u660e\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6309\u94ae1\u5360 1\/3 \u7a7a\u95f4<\/li>\n\n\n\n<li>\u6309\u94ae2\u5360 2\/3 \u7a7a\u95f4<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">4\ufe0f\u20e3 Margin \u4e0e Padding<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u5c5e\u6027<\/th><th>\u4f5c\u7528<\/th><\/tr><\/thead><tbody><tr><td><code>android:layout_margin<\/code><\/td><td>\u63a7\u4ef6\u5916\u95f4\u8ddd\uff0c\u5f71\u54cd\u4e0e\u7236\u5e03\u5c40\u53ca\u5176\u4ed6\u63a7\u4ef6\u8ddd\u79bb<\/td><\/tr><tr><td><code>android:padding<\/code><\/td><td>\u63a7\u4ef6\u5185\u95f4\u8ddd\uff0c\u5f71\u54cd\u5185\u5bb9\u4e0e\u63a7\u4ef6\u8fb9\u754c\u8ddd\u79bb<\/td><\/tr><\/tbody><\/table><\/figure>\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;TextView\n    android:layout_width=&quot;wrap_content&quot;\n    android:layout_height=&quot;wrap_content&quot;\n    android:layout_margin=&quot;16dp&quot;\n    android:padding=&quot;8dp&quot;\n    android:text=&quot;\u5e26\u95f4\u8ddd\u7684\u6587\u672c&quot;\/&gt;\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001\u5e38\u7528\u5e03\u5c40\u7ec4\u5408\u793a\u4f8b<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1\ufe0f\u20e3 \u5782\u76f4 LinearLayout + \u6743\u91cd<\/h3>\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;match_parent&quot;\n    android:orientation=&quot;vertical&quot;&gt;\n\n    &amp;lt;TextView\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;\u4e0a\u534a\u90e8\u5206&quot;\n        android:gravity=&quot;center&quot;\/&gt;\n\n    &amp;lt;TextView\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;\u4e0b\u534a\u90e8\u5206&quot;\n        android:gravity=&quot;center&quot;\/&gt;\n&amp;lt;\/LinearLayout&gt;\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">2\ufe0f\u20e3 RelativeLayout \u5c45\u4e2d\u5e03\u5c40<\/h3>\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;match_parent&quot;&gt;\n\n    &amp;lt;Button\n        android:id=&quot;@+id\/btnCenter&quot;\n        android:layout_width=&quot;wrap_content&quot;\n        android:layout_height=&quot;wrap_content&quot;\n        android:text=&quot;\u5c45\u4e2d\u6309\u94ae&quot;\n        android:layout_centerInParent=&quot;true&quot;\/&gt;\n&amp;lt;\/RelativeLayout&gt;\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">3\ufe0f\u20e3 FrameLayout \u8986\u76d6\u5e03\u5c40<\/h3>\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;\u8986\u76d6\u6587\u5b57&quot;\n        android:layout_gravity=&quot;center&quot;\/&gt;\n&amp;lt;\/FrameLayout&gt;\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001\u603b\u7ed3\u4e0e\u7ecf\u9a8c\u6280\u5de7<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>LinearLayout + \u6743\u91cd<\/strong> \u2192 \u5feb\u901f\u5b9e\u73b0\u6bd4\u4f8b\u5e03\u5c40<\/li>\n\n\n\n<li><strong>RelativeLayout \/ ConstraintLayout<\/strong> \u2192 \u7075\u6d3b\u5bf9\u9f50 \/ \u5c45\u4e2d \/ \u951a\u70b9\u5e03\u5c40<\/li>\n\n\n\n<li><strong>FrameLayout<\/strong> \u2192 \u5806\u53e0 \/ \u8986\u76d6<\/li>\n\n\n\n<li><strong><code>android:layout_*<\/code> \u5c5e\u6027<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li><code>layout_width<\/code> \/ <code>layout_height<\/code>\uff1a\u5c3a\u5bf8<\/li>\n\n\n\n<li><code>layout_margin<\/code>\uff1a\u5916\u95f4\u8ddd<\/li>\n\n\n\n<li><code>layout_gravity<\/code> \/ <code>gravity<\/code>\uff1a\u5bf9\u9f50<\/li>\n\n\n\n<li><code>layout_weight<\/code>\uff1a\u6bd4\u4f8b \/ \u6743\u91cd<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>ConstraintLayout<\/strong> \u2192 \u73b0\u4ee3\u590d\u6742\u5e03\u5c40\u9996\u9009\uff0c\u51cf\u5c11\u5d4c\u5957\uff0c\u63d0\u9ad8\u6027\u80fd<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 Android \u5f00\u53d1\u4e2d\uff0cUI \u754c\u9762\u662f\u901a\u8fc7 \u5e03\u5c40\uff08Layout\uff09 \u6765\u5b9e\u73b0\u7684\uff0c\u5e03&#8230; <a class=\"more-link\" href=\"https:\/\/www.52runoob.com\/index.php\/2025\/12\/25\/android-layout%e5%b8%83%e5%b1%80_androidlayout-2\/\">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-961","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\/961","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=961"}],"version-history":[{"count":1,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/961\/revisions"}],"predecessor-version":[{"id":962,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/961\/revisions\/962"}],"wp:attachment":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/media?parent=961"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/categories?post=961"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/tags?post=961"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}