Compose 中的進階版面配置
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
瞭解如何為 Compose 版面配置建立複雜的設計,並著重於版面配置階段和限制、子組合版面配置和內在測量。
重點
- 版面配置階段是 Compose 的階段,用於定義元素大小和位置。
- 在版面配置階段,UI 樹狀結構中的每個元素都會測量子項,讓父項決定自身大小,並將子項放置在可用的 2D 空間中。
- 如要建構自訂版面配置,請呼叫
Layout
可組合函式,該函式會將可組合內容做為子項。
- 子組合可讓延遲元件在捲動時隨選加入內容。
- 子組合版面配置可能會影響效能。當至少一個子項的組合依附於另一個子項的測量結果時,請使用這項方法。
- 內建函式測量可讓您在實際測量前查詢子項相關資訊。
包含此指南的集合
本指南是精選的快速指南系列之一,涵蓋更廣泛的 Android 開發目標:
顯示清單或格狀
清單和格線可讓應用程式以視覺上賞心悅目且使用者易於取用的形式顯示集合。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-02-06 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-02-06 (世界標準時間)。"],[],[],null,["# Advanced layouts in Compose\n\n\u003cbr /\u003e\n\nSee how to build complex designs for your Compose layouts, focusing on layout\nphase and constraints, subcompose layouts, and intrinsic measurements. \n\nKey points\n----------\n\n- The *layout phase* is the phase of Compose where element sizing and positioning is defined.\n- During the layout phase, each element in the UI tree measures its children, enabling the parent to decide its own size and placing the children in the available 2D space.\n- To build a custom layout, call the [`Layout`](/reference/kotlin/androidx/compose/ui/layout/package-summary#Layout(kotlin.collections.List,androidx.compose.ui.Modifier,androidx.compose.ui.layout.MultiContentMeasurePolicy)) composable, which accepts the composable content as its children.\n- Subcomposition enables lazy components to add content on demand while scrolling.\n- Subcomposed layouts can have an impact on performance. Use this approach when at least one child's composition depends on the result of another child's measurement.\n- Intrinsic measurements let you query children before they're measured.\n\nCollections that contain this guide\n-----------------------------------\n\nThis guide is part of these curated Quick Guide collections that cover\nbroader Android development goals: \n\n### Display a list or grid\n\nLists and grids allow your app to display collections in a visually pleasing form that's easy for users to consume. \n[Quick guide collection](/develop/ui/compose/quick-guides/collections/display-a-list-or-grid) \n\nHave questions or feedback\n--------------------------\n\nGo to our frequently asked questions page and learn about quick guides or reach out and let us know your thoughts. \n[Go to FAQ](/quick-guides/faq) [Leave feedback](https://issuetracker.google.com/issues/new?component=1573691&template=1993320)"]]