با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
می توانید مجموعه داده های بزرگ و محتوای پویا را با شبکه های تنبل مدیریت کنید و عملکرد برنامه را بهبود بخشید. با ترکیببندیهای شبکه تنبل، میتوانید موارد را در یک محفظه قابل پیمایش، که در چندین ستون یا ردیف قرار دارند، نمایش دهید.
سازگاری نسخه
این پیاده سازی مستلزم آن است که minSDK پروژه شما روی سطح API 21 یا بالاتر تنظیم شود.
وابستگی ها
جهت گیری شبکه را تعیین کنید
ترکیبپذیرهای LazyHorizontalGrid و LazyVerticalGrid از نمایش موارد در یک شبکه پشتیبانی میکنند. یک شبکه عمودی تنبل اقلام خود را در یک محفظه قابل پیمایش عمودی نشان میدهد که در چندین ستون قرار دارد، در حالی که شبکههای افقی تنبل رفتار یکسانی در محور افقی دارند.
یک شبکه قابل پیمایش ایجاد کنید
کد زیر یک شبکه اسکرول افقی با سه ستون ایجاد می کند:
@ComposablefunScrollingGrid(){valitemsList=(0..15).toList()valitemModifier=Modifier.border(1.dp,Color.Blue).width(80.dp).wrapContentSize()LazyHorizontalGrid(rows=GridCells.Fixed(3),horizontalArrangement=Arrangement.spacedBy(16.dp),verticalArrangement=Arrangement.spacedBy(16.dp)){items(itemsList){Text("Item is $it",itemModifier)}item{Text("Single item",itemModifier)}}}
قابلیت ترکیب LazyHorizontalGrid جهت افقی شبکه را تعیین می کند.
برای ایجاد یک شبکه عمودی، به جای آن از LazyVerticalGrid استفاده کنید.
ویژگی rows نحوه چیدمان محتوای شبکه را مشخص می کند.
برای یک شبکه عمودی، از ویژگی columns برای مشخص کردن آرایش استفاده کنید.
items(itemsList)itemsList به LazyHorizontalGrid اضافه می کند. لامبدا یک Text قابل نوشتن برای هر آیتم ارائه می دهد و متن را روی توضیحات مورد تنظیم می کند.
item() یک آیتم را به LazyHorizontalGrid اضافه می کند در حالی که لامبدا یک Text به روشی مشابه به items() رندر می کند.
برای ایجاد یک شبکه با بیشترین تعداد ردیف ممکن، تعداد ردیف ها را با استفاده از GridCells.Adaptive تنظیم کنید.
در کد زیر مقدار 20.dp مشخص می کند که هر ستون حداقل 20.dp باشد و همه ستون ها دارای عرض یکسان باشند. اگر پهنای صفحه 88.dp باشد، 4 ستون هر کدام با 22.dp وجود دارد.
نتایج
شکل 1. یک شبکه اسکرول افقی با استفاده از LazyHorizontalGrid .
مجموعه هایی که حاوی این راهنما هستند
این راهنما بخشی از مجموعههای راهنمای Quick Guide است که اهداف توسعه Android گستردهتری را پوشش میدهد:
نمایش یک لیست یا شبکه
فهرستها و شبکهها به برنامه شما اجازه میدهند مجموعهها را به شکل بصری دلپذیری نمایش دهد که مصرف آن برای کاربران آسان است.
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و 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,["# Create a scrollable grid\n\n\u003cbr /\u003e\n\nYou can manage large datasets and dynamic content with lazy grids, improving app\nperformance. With lazy grid composables, you can display items in a scrollable\ncontainer, spanned across multiple columns or rows.\n\nVersion compatibility\n---------------------\n\nThis implementation requires that your project minSDK be set to API level 21 or\nhigher.\n\n### Dependencies\n\n### Kotlin\n\n\u003cbr /\u003e\n\n```kotlin\n implementation(platform(\"androidx.compose:compose-bom:2025.08.00\"))\n \n```\n\n\u003cbr /\u003e\n\n### Groovy\n\n\u003cbr /\u003e\n\n```groovy\n implementation platform('androidx.compose:compose-bom:2025.08.00')\n \n```\n\n\u003cbr /\u003e\n\nDecide grid orientation\n-----------------------\n\nThe [`LazyHorizontalGrid`](/reference/kotlin/androidx/compose/foundation/lazy/grid/package-summary#LazyHorizontalGrid(androidx.compose.foundation.lazy.grid.GridCells,androidx.compose.ui.Modifier,androidx.compose.foundation.lazy.grid.LazyGridState,androidx.compose.foundation.layout.PaddingValues,kotlin.Boolean,androidx.compose.foundation.layout.Arrangement.Horizontal,androidx.compose.foundation.layout.Arrangement.Vertical,androidx.compose.foundation.gestures.FlingBehavior,kotlin.Boolean,kotlin.Function1)) and [`LazyVerticalGrid`](/reference/kotlin/androidx/compose/foundation/lazy/grid/package-summary#LazyVerticalGrid(androidx.compose.foundation.lazy.grid.GridCells,androidx.compose.ui.Modifier,androidx.compose.foundation.lazy.grid.LazyGridState,androidx.compose.foundation.layout.PaddingValues,kotlin.Boolean,androidx.compose.foundation.layout.Arrangement.Vertical,androidx.compose.foundation.layout.Arrangement.Horizontal,androidx.compose.foundation.gestures.FlingBehavior,kotlin.Boolean,kotlin.Function1)) composables provide\nsupport for displaying items in a grid. A lazy vertical grid displays its items\nin a vertically scrollable container, spanned across multiple columns, while\nlazy horizontal grids have the same behavior on the horizontal axis.\n\n### Create a scrollable grid\n\nThe following code creates a horizontal scrolling grid with three columns:\n\n\n```kotlin\n@Composable\nfun ScrollingGrid() {\n val itemsList = (0..15).toList()\n\n val itemModifier = Modifier\n .border(1.dp, Color.Blue)\n .width(80.dp)\n .wrapContentSize()\n\n LazyHorizontalGrid(\n rows = GridCells.Fixed(3),\n horizontalArrangement = Arrangement.spacedBy(16.dp),\n verticalArrangement = Arrangement.spacedBy(16.dp)\n ) {\n items(itemsList) {\n Text(\"Item is $it\", itemModifier)\n }\n\n item {\n Text(\"Single item\", itemModifier)\n }\n }\n}https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/compose/snippets/src/main/java/com/example/compose/snippets/lists/LazyListSnippets.kt#L835-L857\n```\n\n\u003cbr /\u003e\n\n### Key points about the code\n\n- The `LazyHorizontalGrid` composable determines the horizontal orientation of the grid.\n - To create a vertical grid, use the `LazyVerticalGrid` instead.\n- The `rows` property specifies how to arrange the grid content.\n - For a vertical grid, use the `columns` property to specify the arrangement.\n- [`items(itemsList)`](/reference/kotlin/androidx/compose/foundation/lazy/LazyListScope#items(kotlin.Int,kotlin.Function1,kotlin.Function1,kotlin.Function2)) adds `itemsList` to `LazyHorizontalGrid`. The lambda renders a [`Text`](/reference/kotlin/androidx/compose/material/package-summary#Text(androidx.compose.ui.text.AnnotatedString,androidx.compose.ui.Modifier,androidx.compose.ui.graphics.Color,androidx.compose.ui.unit.TextUnit,androidx.compose.ui.text.font.FontStyle,androidx.compose.ui.text.font.FontWeight,androidx.compose.ui.text.font.FontFamily,androidx.compose.ui.unit.TextUnit,androidx.compose.ui.text.style.TextDecoration,androidx.compose.ui.text.style.TextAlign,androidx.compose.ui.unit.TextUnit,androidx.compose.ui.text.style.TextOverflow,kotlin.Boolean,kotlin.Int,kotlin.Int,kotlin.collections.Map,kotlin.Function1,androidx.compose.ui.text.TextStyle)) composable for each item and set the text to the item description.\n- [`item()`](/reference/kotlin/androidx/compose/foundation/lazy/LazyListScope#item(kotlin.Any,kotlin.Any,kotlin.Function1)) adds a single item to `LazyHorizontalGrid` while the lambda renders a single `Text` composable in a similar manner to `items()`.\n- [`GridCells.Fixed`](/reference/kotlin/androidx/compose/foundation/lazy/grid/GridCells.Fixed) defines the number of rows or columns.\n- To create a grid with as many rows as possible, set the number of rows using\n [`GridCells.Adaptive`](/reference/kotlin/androidx/compose/foundation/lazy/grid/GridCells.Adaptive).\n\n In the following code, the `20.dp` value\n specifies that every column is at least 20.dp, and all columns have equal\n widths. If the screen is 88.dp wide, there are 4 columns at 22.dp each.\n\n LazyVerticalGrid(\n columns = GridCells.Adaptive(minSize = 20.dp)\n )\n\nResults\n-------\n\n\u003cbr /\u003e\n\n**Figure 1.** A horizontal scrollable grid using `LazyHorizontalGrid`.\n\n\u003cbr /\u003e\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\n### Display interactive components\n\nLearn how composable functions can enable you to easily create beautiful UI components based on the Material Design design system. \n[Quick guide collection](/develop/ui/compose/quick-guides/collections/display-interactive-components) \n\n### Compose basics (video collection)\n\nThis series of videos introduces various Compose APIs, quickly showing you what's available and how to use them. \n[Quick guide collection](/develop/ui/compose/quick-guides/collections/compose-basics) \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)"]]