Android中的Linear Layout

來源:互聯網
上載者:User
今天在看android開發的文章,看到線性布局的時候,看不明白裡面的layout_weight屬性,所以乾脆翻譯出來研究,以下是原文的翻譯

 -------------------------------------------------------------------------------------------------------

LinearLayout aligns all children in a single direction — vertically or horizontally, depending on how you define the orientation attribute. All children are stacked one after the other, so a vertical list will only have one child per row, no matter how wide they are, and a horizontal list will only be one row high (the height of the tallest child, plus padding). A LinearLayout respects margins between children and the gravity (right, center, or left alignment) of each child.

線性布局已一個方向來排列所有的孩子-垂直的或水平的,這取決於你如何去定義orientation屬性。所有的孩子一個接一個的靠在一起,因此一個垂直列表將在每一行上只有一個孩子,無論他們多寬,並一個水平列表將只有一個行高(取決於最高孩子的高度,不足的添加空白)。一個線性布局主要用於維護空白邊在孩子和孩子的gravity(不知道這個詞怎麼翻譯,不過應該是和布局有關係)。LinearLayout also supports assigning a weight to individual children. This attribute assigns an "importance" value to a view, and allows it to expand to fill any remaining space in the parent view. Child views can specify an integer weight value, and then any remaining space in the view group is assigned to children in the proportion of their declared weight. Default weight is zero. For example, if there are three text boxes and two of them declare a weight of 1, while the other is given no weight (0), the third text box without weight will not grow and will only occupy the area required by its content. The other two will expand equally to fill the space remaining after all three boxes are measured. If the third box is then given a weight of 2 (instead of 0), then it is now declared "more important" than both the others, so it gets half the total remaining space, while the first two share the rest equally.線性布局也支援分配一個權重到獨立的孩子。這個屬性分配一個“重要的”值給視圖,並允許它擴充填充剩餘的空間在父視圖上。孩子視圖可以指定一個整型權重值,然後在這個視圖組裡的剩餘空間將以孩子權重的百分比來分配。預設權重是0.例如,如果有3個文字框,其中2個的權重是1,當剩下那個被賦予0時,第3個文字框因為沒有權重而不會擴充並且以內容地區為基準。另外2個會平均分配剩餘的空間。如果第3個文字框被賦予了權重2,那麼就意味著它被聲明為比其他兩個“更重要”。因此它將佔據所有剩餘空間的一半,剩餘空間是布局完1,2兩個文字框後的空間。Tip: To create a proportionate size layout on the screen, create a container view group object with the layout_width and layout_height attributes set to fill_parent; assign the children height or width to 0 (zero); then assign relative weight values to each child, depending on what proportion of the screen each should have.提示:建立一個按百分比大小布局的螢幕,建立一個[內容] 檢視組以fill_parent來設定layout_width和layout_height屬性;設定孩子的高度和寬度為0;然後分配相關的權重值到每一個孩子,權重值取決於孩子要佔據螢幕的百分比。Within a horizontal LinearLayout, items are aligned by the position of their text base line (the first line of the first list element — topmost or leftmost — is considered the reference line). This is so that people scanning elements in a form shouldn't have to jump up and down to read element text in neighboring elements. This can be turned off by setting android:baselineAligned="false" in the layout XML.在一個水平線性布局中,成員被排列到他們文本的基準位置(列表的第一個元素的第一行-頂端或左邊-這個被認為輔助線)。這是為了讓人們在一個表單上掃描元素時,不至於上下跳動的在相鄰的元素中讀取文本。這個屬性可以被關閉,通過在layout的XML中設定android:baselineAligned="false"。
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.