स्नैप स्क्रोलिंग की सुविधा चालू करने के लिए बटन बनाना
संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
उपयोगकर्ता को सूची में किसी खास पॉइंट पर स्नैप स्क्रोल करने की सुविधा देने के लिए, एक बटन दिखाया जा सकता है. इससे समय की बचत होती है और उपयोगकर्ता जुड़ाव बढ़ता है.
वर्शन के साथ काम करना
इसे लागू करने के लिए, ज़रूरी है कि आपके प्रोजेक्ट का minSDK एपीआई लेवल 21 या उससे ज़्यादा पर सेट हो.
डिपेंडेंसी
स्नैप स्क्रोलिंग की सुविधा चालू करने के लिए बटन बनाना
10 आइटम वाली वर्टिकल लेज़ी सूची में, स्नैप स्क्रोलिंग के लिए बटन बनाने के लिए, नीचे दिए गए कोड का इस्तेमाल करें:
LazyColumn के स्क्रोल की स्थिति को चुनी गई जगह पर सेव करने के लिए, listState ऑब्जेक्ट का इस्तेमाल करता है.
listState.animateScrollToItem को कॉल करने के लिए कोरुटाइन लॉन्च करता है. यह स्क्रोलिंग ऐक्शन को ऐनिमेट करते हुए, इंडेक्स किए गए आइटम पर स्क्रोल करता है.
नतीजे
पहली इमेज. स्नैप स्क्रोल बटन वाली वर्टिकल स्क्रोलिंग सूची.
ऐसे संग्रह जिनमें यह गाइड शामिल है
यह गाइड, चुने गए क्विक गाइड के कलेक्शन का हिस्सा है. इसमें 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 button to enable snap scrolling\n\n\u003cbr /\u003e\n\nYou can display a button to let a user snap scroll to a specific point in a\nlist, saving time and increasing user engagement.\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 implementation(\"androidx.compose.material3:material3\")\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 implementation 'androidx.compose.material3:material3'\n \n```\n\n\u003cbr /\u003e\n\nCreate a button to enable snap scrolling\n----------------------------------------\n\nUse the following code to create a button for smooth snap scrolling in a\nvertical lazy list with 10 items:\n\n\n```kotlin\n@Composable\nfun MessageList(modifier: Modifier = Modifier) {\n val listState = rememberLazyListState()\n val coroutineScope = rememberCoroutineScope()\n\n LazyColumn(state = listState, modifier = Modifier.height(120.dp)) {\n items(10) { index -\u003e\n Text(\n modifier = Modifier.height(40.dp),\n text = \"Item $index\"\n )\n }\n }\n\n Button(onClick = {\n coroutineScope.launch {\n listState.animateScrollToItem(index = 0)\n }\n }) {\n Text(text = \"Go top\")\n }\n}https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/compose/snippets/src/main/java/com/example/compose/snippets/lists/LazyListSnippets.kt#L810-L831\n```\n\n\u003cbr /\u003e\n\n### Key points about the code\n\n- Uses the [`listState`](/reference/kotlin/androidx/compose/foundation/lazy/LazyListState) object to remember the scroll state of [`LazyColumn`](/reference/kotlin/androidx/compose/foundation/lazy/package-summary#LazyColumn(androidx.compose.ui.Modifier,androidx.compose.foundation.lazy.LazyListState,androidx.compose.foundation.layout.PaddingValues,kotlin.Boolean,androidx.compose.foundation.layout.Arrangement.Vertical,androidx.compose.ui.Alignment.Horizontal,androidx.compose.foundation.gestures.FlingBehavior,kotlin.Boolean,kotlin.Function1)) to the selected position.\n- Launches a coroutine to call [`listState.animateScrollToItem`](/reference/kotlin/androidx/compose/foundation/lazy/LazyListState#animateScrollToItem(kotlin.Int,kotlin.Int)), which scrolls to the indexed item while animating the scrolling action.\n\nResults\n-------\n\n**Figure 1.** A vertical scrolling list with a snap scroll button.\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)"]]