{"id":133,"date":"2023-02-18T19:36:16","date_gmt":"2023-02-18T11:36:16","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=133"},"modified":"2023-02-18T19:36:43","modified_gmt":"2023-02-18T11:36:43","slug":"android-basic-linearlayout","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/18\/android-basic-linearlayout\/","title":{"rendered":"Android\u57fa\u7840\u4e4bLinearLayout"},"content":{"rendered":"<h2>LinearLayout\u5206\u5272\u7ebf<\/h2>\n<p>1) \u76f4\u63a5\u5728\u5e03\u5c40\u4e2d\u6dfb\u52a0\u4e00\u4e2aview<\/p>\n<pre><code class=\"language-xml\">&lt;View\n    android:layout_width=&quot;match_parent&quot;\n    android:layout_height=&quot;1px&quot;\n    android:background=&quot;#000000&quot;\n    \/&gt;<\/code><\/pre>\n<p><!-- more --><\/p>\n<p>2) \u4f7f\u7528LinearLayout\u7684divider\u5c5e\u6027<\/p>\n<pre><code class=\"language-xml\">&lt;LinearLayout \n    android:divider=&quot;@drawable\/divider&quot;\n    android:showDividers=&quot;middle&quot;\n    android:dividerPadding=&quot;10dp&quot;<\/code><\/pre>\n<h2>LinearLayout\u7684layout_weight\u5360\u6bd4\u8ba1\u7b97<\/h2>\n<p>\u5047\u8bbe2\u4e2a\u5b50\u63a7\u4ef6\u8bbe\u8ba1\u7684weight\u503c\u5206\u522b\u4e3aa,b(a+b=1)\uff0c\u5219\u63a7\u4ef6\u7684\u5b9e\u9645\u5360\u6bd4\u4e3a<\/p>\n<ul>\n<li>1-a\/(a+b)<\/li>\n<li>1-b\/(a+b)<\/li>\n<\/ul>\n<p>\u5047\u8bbe3\u4e2a\u5b50\u63a7\u4ef6\u8bbe\u8ba1\u7684weight\u503c\u5206\u522b\u4e3aa,b,c(a+b+c=1)\uff0c\u5219\u63a7\u4ef6\u7684\u5b9e\u9645\u5360\u6bd4\u4e3a<\/p>\n<ul>\n<li>1-2a\/(a+b+c)<\/li>\n<li>1-2b\/(a+b+c)<\/li>\n<li>1-2c\/(a+b+c)<\/li>\n<\/ul>\n<h2>LinearLayout\u7684layout_gravity<\/h2>\n<ul>\n<li>\n<p>\u5f53 android:orientation=&quot;vertical&quot; \u65f6\uff0c\u53ea\u6709\u6c34\u5e73\u65b9\u5411\u7684\u8bbe\u7f6e\u624d\u8d77\u4f5c\u7528\uff0c\u5782\u76f4\u65b9\u5411\u7684\u8bbe\u7f6e\u4e0d\u8d77\u4f5c\u7528\u3002<br \/>\n\u5373\uff1aleft\u3001right\u3001center_horizontal \u662f\u751f\u6548\u7684\u3002 <\/p>\n<\/li>\n<li>\n<p>\u5f53 android:orientation=&quot;horizontal&quot; \u65f6\uff0c\u53ea\u6709\u5782\u76f4\u65b9\u5411\u7684\u8bbe\u7f6e\u624d\u8d77\u4f5c\u7528\uff0c\u6c34\u5e73\u65b9\u5411\u7684\u8bbe\u7f6e\u4e0d\u8d77\u4f5c\u7528\u3002<br \/>\n\u5373\uff1atop\u3001bottom\u3001center_vertical \u662f\u751f\u6548\u7684\u3002<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"language-xml\">&lt;LinearLayout\n    android:layout_width=&quot;wrap_content&quot;\n    android:layout_height=&quot;wrap_content&quot;\n    android:orientation=&quot;horizontal&quot;\n    &gt;\n    &lt;TextView\n        android:layout_width=&quot;wrap_content&quot;\n        android:layout_height=&quot;wrap_content&quot;\n        android:text=&quot;\u767b\u9646&quot;\n        android:layout_gravity=&quot;left&quot;\n        \/&gt;\n    &lt;TextView\n        android:layout_width=&quot;wrap_content&quot;\n        android:layout_height=&quot;wrap_content&quot;\n        android:text=&quot;\u6ce8\u518c&quot;\n        android:layout_gravity=&quot;right&quot;\n        \/&gt;\n&lt;\/LinearLayout&gt;<\/code><\/pre>\n<p>\u5f0a\u7aef\uff1a\u5982\u679c\u6c34\u5e73\u65b9\u5411\u8bbe\u7f6e\u5de6\u53f3\u5bf9\u9f50\uff0c\u5c31\u4f1a\u51fa\u73b0\u5982\u4e0b\u6548\u679c<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.yezhou.me\/AppBlog\/images\/Android\/Android_LinearLayout_layout_gravity.jpg\" alt=\"\u6c34\u5e73\u65b9\u5411\u8bbe\u7f6e\u5de6\u53f3\u5bf9\u9f50\" \/><\/p>\n<blockquote>\n<p>\u4f7f\u7528LinearLayout\u7684\u95ee\u9898\uff1a\u5f53\u754c\u9762\u6bd4\u8f83\u590d\u6742\u7684\u65f6\u5019\uff0c\u9700\u8981\u5d4c\u5957\u591a\u5c42\u7684 LinearLayout\uff0c\u8fd9\u6837\u5c31\u4f1a\u964d\u4f4eUI Render\u7684\u6548\u7387(\u6e32\u67d3\u901f\u5ea6)\u3002\u603b\u7ed3\u5c31\u662f\uff1a\u5c3d\u91cf\u4f7f\u7528RelativeLayout + LinearLayout\u7684weight\u5c5e\u6027\u642d\u914d\u4f7f\u7528\u3002<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>LinearLayout\u5206\u5272\u7ebf 1) \u76f4\u63a5\u5728\u5e03\u5c40\u4e2d\u6dfb\u52a0\u4e00\u4e2aview &lt;View android:layo [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61],"tags":[],"class_list":["post-133","post","type-post","status-publish","format-standard","hentry","category-android-basic"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/133","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=133"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/133\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}