Load Drawable in recyclerView when it it is scrolled to inside ScrollView

85 Views Asked by At

I am using a ScrollView which contains multiple views one of which is a recycler view. Recycler view contains VectorDrawables which are loaded as soon as the application is run, due to which animations are loaded off-screen, and by the time I scroll down to the recycler view the animations get over.

Currently setting up of AnimatedVectorDrawables is done in onBindViewHolder() of the adapter.

override fun onBindViewHolder(holder: SuccessMetricViewHolder, position: Int) {
    val successMetric = dataList[position]

    with(holder.binding) {
        tvHeading.text = successMetric.count
        tvDescription.text = successMetric.name
    }

    with(holder.binding.ivBannerImage) {
        when (successMetric.name) {
            "Instapreps Location" -> {
                setBackgroundResource(R.drawable.loc_avd_anim)
            }
            "Confidence Diagnosed" -> {
                setBackgroundResource(R.drawable.confi_avd_anim)

            }
            "Questions Solved" -> {
                setBackgroundResource(R.drawable.ques_avd_anim)
            }
            "Play Store Rating" -> {
                setBackgroundResource(R.drawable.stars_avd_anim)
            }
        }
        animatedVectorDrawable = background as AnimatedVectorDrawable
        animatedVectorDrawable.start()
    }
}

I want the VectorDrawables to load when the recycler view is scrolled to and is visible on the screen.

1

There are 1 best solutions below

0
On

I can't advise you to use glide/Picasso image loading library. But, maybe using pagination in the RecyclerView which helps to await loading of other views onScroll

This might help