Last active
October 25, 2022 12:38
-
-
Save rodrigomartind/cbb0e83940920902a6a728d83092f0c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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