با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
با استفاده از نشانگرهای صفحه، می توانید به کاربران خود کمک کنید تا موقعیت فعلی خود را در محتوای برنامه خود درک کنند و یک نشانه بصری از پیشرفت ارائه دهید. این نشانه های ناوبری زمانی مفید هستند که محتوا را به صورت متوالی ارائه می کنید، مانند پیاده سازی چرخ فلک، گالری تصاویر و نمایش اسلاید، یا صفحه بندی در لیست ها.
سازگاری نسخه
این پیاده سازی مستلزم آن است که minSDK پروژه شما روی سطح API 21 یا بالاتر تنظیم شود.
وابستگی ها
یک پیجر افقی با نشانگر صفحه سفارشی ایجاد کنید
کد زیر یک پیجر افقی ایجاد میکند که دارای نشانگر صفحه است و به کاربر نشانههای بصری میدهد که تعداد صفحات وجود دارد و کدام صفحه قابل مشاهده است:
کد یک HorizontalPager پیاده سازی می کند که به شما امکان می دهد به صورت افقی بین صفحات مختلف محتوا بکشید. در این حالت هر صفحه شماره صفحه را نمایش می دهد.
تابع rememberPagerState() پیجر را مقداردهی اولیه می کند و تعداد صفحات را 4 تنظیم می کند. این تابع یک شیء حالت ایجاد می کند که صفحه جاری را ردیابی می کند و به شما امکان می دهد پیجر را کنترل کنید.
ویژگی pagerState.currentPage برای تعیین اینکه کدام نشانگر صفحه باید برجسته شود استفاده می شود.
صفحه indictator در پیجری ظاهر میشود که با اجرای Row پوشانده شده است.
یک دایره 16 dp برای هر صفحه در پیجر رسم می شود. نشانگر صفحه فعلی به صورت DarkGray نمایش داده می شود، در حالی که بقیه دایره های نشانگر LightGray هستند.
Text composable در HorizontalPager متن "Page: [شماره صفحه]" را در هر صفحه نمایش می دهد.
نتایج
شکل 1. پیجر نشانگر دایره ای را در زیر محتوا نشان می دهد.
مجموعه هایی که حاوی این راهنما هستند
این راهنما بخشی از مجموعههای راهنمای 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,["\u003cbr /\u003e\n\nUsing page indicators, you can help your users understand their current position\nwithin your app's content, providing a visual indication of progress. These\nnavigational cues are useful when you present content sequentially, such as\ncarousel implementations, image galleries and slideshows, or pagination in\nlists.\n\nVersion compatibility\n\nThis implementation requires that your project minSDK be set to API level 21 or\nhigher.\n\nDependencies\n\nCreate a horizontal pager with a custom page indicator\n\nThe following code creates a horizontal pager that has a page indicator, giving\nthe user visual cues for how many pages there are and which page is\nvisible:\n\n\n```kotlin\nval pagerState = rememberPagerState(pageCount = {\n 4\n})\nHorizontalPager(\n state = pagerState,\n modifier = Modifier.fillMaxSize()\n) { page -\u003e\n // Our page content\n Text(\n text = \"Page: $page\",\n )\n}\nRow(\n Modifier\n .wrapContentHeight()\n .fillMaxWidth()\n .align(Alignment.BottomCenter)\n .padding(bottom = 8.dp),\n horizontalArrangement = Arrangement.Center\n) {\n repeat(pagerState.pageCount) { iteration -\u003e\n val color = if (pagerState.currentPage == iteration) Color.DarkGray else Color.LightGray\n Box(\n modifier = Modifier\n .padding(2.dp)\n .clip(CircleShape)\n .background(color)\n .size(16.dp)\n )\n }\n}https://github.com/android/snippets/blob/30ed522851a9273c94afcd3a4c30bf674346ad18/compose/snippets/src/main/java/com/example/compose/snippets/layouts/PagerSnippets.kt#L381-L411\n```\n\n\u003cbr /\u003e\n\nKey points about the code\n\n- The code implements a [`HorizontalPager`](/reference/kotlin/androidx/compose/foundation/pager/package-summary#HorizontalPager(androidx.compose.foundation.pager.PagerState,androidx.compose.ui.Modifier,androidx.compose.foundation.layout.PaddingValues,androidx.compose.foundation.pager.PageSize,kotlin.Int,androidx.compose.ui.unit.Dp,androidx.compose.ui.Alignment.Vertical,androidx.compose.foundation.gestures.TargetedFlingBehavior,kotlin.Boolean,kotlin.Boolean,kotlin.Function1,androidx.compose.ui.input.nestedscroll.NestedScrollConnection,androidx.compose.foundation.gestures.snapping.SnapPosition,kotlin.Function2)), which lets you swipe horizontally between different pages of content. In this case, each page displays the page number.\n- The `rememberPagerState()` function initializes the pager and sets the number of pages to 4. This function creates a state object that tracks the current page, and lets you control the pager.\n- The [`pagerState.currentPage`](/reference/kotlin/androidx/compose/foundation/pager/PagerState#currentPage()) property is used to determine which page indicator should be highlighted.\n- The page indictator appears in a pager overlaid by a [`Row`](/reference/kotlin/androidx/compose/foundation/layout/package-summary#Row(androidx.compose.ui.Modifier,androidx.compose.foundation.layout.Arrangement.Horizontal,androidx.compose.ui.Alignment.Vertical,kotlin.Function1)) implementation.\n- A 16 dp circle is drawn for each page in the pager. The indicator for the current page is displayed as `DarkGray`, while the rest of the indicator circles are `LightGray`.\n- The [`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 within the `HorizontalPager` displays the text \"Page: \\[page number\\]\" on each page.\n\nResults **Figure 1.** Pager showing a circle indicator under the content.\n\nCollections that contain this guide\n\nThis guide is part of these curated Quick Guide collections that cover\nbroader Android development goals: \n\nDisplay a list or grid \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\nDisplay interactive components \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\nHave questions or feedback \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)"]]