Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to prevent scrolling multiple items, and only scroll one item at a time ? #92

Open
evoionosp opened this issue Oct 24, 2022 · 2 comments
Labels
question Further information is requested

Comments

@evoionosp
Copy link

No description provided.

@ImaginativeShohag
Copy link
Owner

Can you give me more context? Video and/or code. You can check out the samples for the best ways to implement.

@ImaginativeShohag ImaginativeShohag added the question Further information is requested label Mar 29, 2023
@rethinavelsmitch
Copy link

rethinavelsmitch commented Jan 29, 2024

@ImaginativeShohag This is the video for reference. How can I scroll only one item and prevent multiple items.?

Here is my source code:

<org.imaginativeworld.whynotimagecarousel.ImageCarousel
          android:id="@+id/carousel"
          android:layout_width="match_parent"
          android:layout_height="200dp"
          app:carouselBackground="@android:color/transparent"
          app:carouselGravity="CENTER"
          app:carouselPaddingBottom="0dp"
          app:carouselPaddingTop="0dp"
          app:carouselType="BLOCK"
          app:infiniteCarousel="true"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toBottomOf="@id/ht_pgm_overview_title"
          app:scaleOnScroll="true"
          app:scalingFactor="0.25"
          app:showBottomShadow="false"
          app:showCaption="false"
          app:autoWidthFixing="true"
          app:showIndicator="false"
          app:showNavigationButtons="false"
          app:showTopShadow="false"
          app:touchToPause="true" />

` val carousel: ImageCarousel = binding.carousel
carousel.registerLifecycle(lifecycle)

    val list = mutableListOf<CarouselItem>()
    // (0..5).forEach { index ->
    (0..4).forEach { index ->

        val item = if (index < currentLevel)
            levelImageArray[index]
        else levelImageArrayDisabled[index]

        list.add(CarouselItem(item, index.toString()))
    }
    carousel.setData(list)

    carousel.onScrollListener = object : CarouselOnScrollListener {
        override fun onScrollStateChanged(
            recyclerView: RecyclerView,
            newState: Int,
            position: Int,
            carouselItem: CarouselItem?,
        ) {
            super.onScrollStateChanged(recyclerView, newState, position, carouselItem)
            binding.tasksViewPager.currentItem = position
            setRangeSliderValues(currentLevel, position)
         }
    }

    carousel.carouselListener = object : CarouselListener {
        override fun onCreateViewHolder(
            layoutInflater: LayoutInflater,
            parent: ViewGroup,
        ): ViewBinding {
            return FragmentHtLevelIndicatorBinding.inflate(layoutInflater, parent, false)
        }

        override fun onBindViewHolder(binding: ViewBinding, item: CarouselItem, position: Int) {
            val currentBinding = binding as FragmentHtLevelIndicatorBinding
            setImage(currentBinding.imgLevel, item.imageDrawable ?: R.drawable.ht_level_one)
            val level = item.caption?.toInt()?.plus(1)
            currentBinding.txtLevel.text = getString(R.string.level_with_value, level)

            if (position < currentLevel) {
                currentBinding.txtLevel.setTextColor(getColor(R.color.yellow_deep_dark))
            } else {
                currentBinding.txtLevel.setTextColor(getColor(R.color.grey_8_opacity))
            }
        }
    }`
Screen_recording_20240129_170550.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants