संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
लेज़ी ग्रिड की मदद से, बड़े डेटासेट और डाइनैमिक कॉन्टेंट को मैनेज किया जा सकता है. इससे ऐप्लिकेशन की परफ़ॉर्मेंस बेहतर होती है. लेज़ी ग्रिड कॉम्पोज़ेबल की मदद से, आइटम को स्क्रोल किए जा सकने वाले ऐसे कंटेनर में दिखाया जा सकता है जो कई कॉलम या पंक्तियों में फैला हो.
वर्शन के साथ काम करना
इसे लागू करने के लिए, ज़रूरी है कि आपके प्रोजेक्ट का minSDK एपीआई लेवल 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), LazyHorizontalGrid में itemsList जोड़ता है. यह लेम्ब्डा फ़ंक्शन, हर आइटम के लिए एक Text कॉम्पोज़ेबल रेंडर करता है और टेक्स्ट को आइटम के ब्यौरे पर सेट करता है.
item(), LazyHorizontalGrid में एक आइटम जोड़ता है, जबकि लैम्ब्डा फ़ंक्शन, items() की तरह ही एक Text कॉम्पोज़ेबल को रेंडर करता है.
ज़्यादा से ज़्यादा लाइनों वाला ग्रिड बनाने के लिए, GridCells.Adaptive का इस्तेमाल करके लाइनों की संख्या सेट करें.
नीचे दिए गए कोड में, 20.dp वैल्यू से पता चलता है कि हर कॉलम कम से कम 20.dp है और सभी कॉलम की चौड़ाई एक जैसी है. अगर स्क्रीन 88.dp चौड़ी है, तो इसमें चार कॉलम होंगे और हर कॉलम 22.dp चौड़ा होगा.
नतीजे
पहली इमेज.LazyHorizontalGrid का इस्तेमाल करके, हॉरिज़ॉन्टल तरीके से स्क्रोल किया जा सकने वाला ग्रिड.
ऐसे संग्रह जिनमें यह गाइड शामिल है
यह गाइड, चुने गए क्विक गाइड के कलेक्शन का हिस्सा है. इसमें Android डेवलपमेंट के बड़े लक्ष्यों के बारे में बताया गया है:
सूची या ग्रिड दिखाना
सूचियों और ग्रिड की मदद से, आपके ऐप्लिकेशन में संग्रहों को ऐसे दिखाया जा सकता है कि वे उपयोगकर्ताओं को देखने में अच्छे लगें और उन्हें आसानी से समझ आएं.
जानें कि कॉम्पोज़ेबल फ़ंक्शन की मदद से, Material Design डिज़ाइन सिस्टम के आधार पर, आसानी से खूबसूरत यूज़र इंटरफ़ेस (यूआई) कॉम्पोनेंट कैसे बनाए जा सकते हैं.
इस वीडियो सीरीज़ में, Compose के अलग-अलग एपीआई के बारे में बताया गया है. इससे आपको यह जानने में मदद मिलेगी कि कौनसे एपीआई उपलब्ध हैं और उन्हें कैसे इस्तेमाल किया जा सकता है.
इस पेज पर मौजूद कॉन्टेंट और कोड सैंपल कॉन्टेंट के लाइसेंस में बताए गए लाइसेंस के हिसाब से हैं. 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,["# 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)"]]