เลย์เอาต์ขั้นสูงในช่องการเขียน
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ดูวิธีสร้างการออกแบบที่ซับซ้อนสำหรับเลย์เอาต์ Compose โดยเน้นที่ระยะและข้อจำกัดของเลย์เอาต์ เลย์เอาต์ย่อยของคอมโพสิท และการวัดผลโดยประมาณ
ข้อมูลสำคัญ
- ระยะการวางเลย์เอาต์คือระยะของ Compose ที่กําหนดขนาดและตําแหน่งองค์ประกอบ
- ในระหว่างระยะการจัดวาง องค์ประกอบแต่ละรายการในต้นไม้ UI จะวัดองค์ประกอบย่อย ซึ่งช่วยให้องค์ประกอบหลักตัดสินใจเกี่ยวกับขนาดของตนเองและวางองค์ประกอบย่อยในพื้นที่ 2 มิติที่มีอยู่ได้
- หากต้องการสร้างเลย์เอาต์ที่กำหนดเอง ให้เรียกใช้คอมโพสิเบิล
Layout
ซึ่งรับเนื้อหาคอมโพสิเบิลเป็นองค์ประกอบย่อย
- องค์ประกอบย่อยช่วยให้คอมโพเนนต์แบบ Lazy เพิ่มเนื้อหาตามต้องการขณะเลื่อน
- เลย์เอาต์ที่คอมโพสย่อยอาจส่งผลต่อประสิทธิภาพ ใช้แนวทางนี้เมื่อองค์ประกอบของเด็กอย่างน้อย 1 คนขึ้นอยู่กับผลการวัดของเด็กอีกคน
- การวัดค่าโดยประมาณช่วยให้คุณค้นหาข้อมูลเกี่ยวกับเด็กได้ก่อนที่จะทำการวัด
คอลเล็กชันที่มีคู่มือนี้
คู่มือนี้เป็นส่วนหนึ่งของคอลเล็กชันคู่มือฉบับย่อที่มีการดูแลจัดการซึ่งครอบคลุมเป้าหมายการพัฒนา Android ที่กว้างขึ้น ดังนี้
แสดงรายการหรือตารางกริด
รายการและตารางกริดช่วยให้แอปแสดงคอลเล็กชันในรูปแบบที่ดึงดูดสายตาและใช้งานง่ายสำหรับผู้ใช้
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-02-06 UTC
[[["เข้าใจง่าย","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 UTC"],[],[],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)"]]