sayyam / carouselview

A simple library to add carousel view in android app.
Apache License 2.0
1.15k stars 260 forks source link

Indicator dots below image #120

Open fauziasf opened 4 years ago

fauziasf commented 4 years ago

can you help me put the indicator dots below the image slider?

Frank1234 commented 4 years ago

some code to get you started...

In your own constraintlayout, also add the indicator:

<com.synnapps.carouselview.CarouselView
    android:id="@+id/image_carousel"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<com.synnapps.carouselview.CirclePageIndicator
    android:id="@+id/_image_carousel_indicator"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/image_carousel" />`

then connect the two manually and disable the default indicator:

productsImageCarousel.setIndicatorVisibility(View.GONE) // we have our own indicator
productsImageCarouselIndicator.apply {

    setViewPager(imageCarousel.containerViewPager)

    isVisible = images.size > 1
    fillColor = resources.getColor(R.color.carouselIndicatorSelected, theme)
    ... etc.
}
ytxmobile98 commented 3 years ago

some code to get you started...

In your own constraintlayout, also add the indicator:

<com.synnapps.carouselview.CarouselView
    android:id="@+id/image_carousel"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<com.synnapps.carouselview.CirclePageIndicator
    android:id="@+id/_image_carousel_indicator"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/image_carousel" />`

then connect the two manually and disable the default indicator:

productsImageCarousel.setIndicatorVisibility(View.GONE) // we have our own indicator
productsImageCarouselIndicator.apply {

    setViewPager(imageCarousel.containerViewPager)

    isVisible = images.size > 1
    fillColor = resources.getColor(R.color.carouselIndicatorSelected, theme)
    ... etc.
}

I am trying to implement a carousel with dots under the image.

Tried to use your lines but getting this error: "error: containerViewPager has private access in CarouselView".

Please help!

Frank1234 commented 3 years ago

It has a public getter, do you use kotlin? In com.synnapps.carouselview.CarouselView:

public CarouselViewPager getContainerViewPager() {
        return containerViewPager;
}