shimmerAnimation

Usage

override fun getItemCount(): Int { return Int.MAX_VALUE } // then update it when the correct size comes

override fun onBindViewHolder(holder: MyViewHolder, position: Int) { val item: Item? = getItem(position) if (item == null) { holder.showPlaceholder() } else { holder.bind(item) } }

val animation = shimmerAnimation()

fun showPlaceholder() { // Shift the timing of fade-in/out for each item by its adapter position. We use the // elapsed real time to make this independent from the timing of method call. animation.currentPlayTime = (SystemClock.elapsedRealtime() - adapterPosition * 30L) % FADE_DURATION animation.start() // Show the placeholder UI. image.setImageResource(R.drawable.image_placeholder) name.text = null name.setBackgroundResource(R.drawable.text_placeholder) }

whenever you bind your items make sure you call animation.end()