Skip to content

Instantly share code, notes, and snippets.

@rodrigomartind
Last active October 25, 2022 12:38
Show Gist options
  • Save rodrigomartind/cbb0e83940920902a6a728d83092f0c8 to your computer and use it in GitHub Desktop.
Save rodrigomartind/cbb0e83940920902a6a728d83092f0c8 to your computer and use it in GitHub Desktop.
import android.graphics.Color
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.helper.widget.Carousel
class ActivityMotionCarouselDemo : AppCompatActivity() {
var colors = intArrayOf(
Color.parseColor("#e57373"),
Color.parseColor("#ce93d8"),
Color.parseColor("#5e35b1"),
Color.parseColor("#9fa8da"),
Color.parseColor("#80cbc4"),
Color.parseColor("#fff59d"),
Color.parseColor("#ffab91"),
Color.parseColor("#cfd8dc")
)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_carousel_demo)
setupCarousel()
}
private fun setupCarousel() {
val carousel = findViewById<Carousel>(R.id.carousel) ?: return
val numImages = colors.size
carousel.setAdapter(object : Carousel.Adapter {
override fun count(): Int {
return numImages
}
override fun populate(view: View, index: Int) {
view.setBackgroundColor(colors[index])
}
override fun onNewItem(index: Int) {
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment