0

I'm using an ImageSwitcher to fade change the background when the screen is touched with a fade effect.

The Working Code

This is how I used to change them before using Glide:

MainActivity:

override fun onCreate(savedInstanceState: Bundle?) {
    ...
    val `in` = AnimationUtils.loadAnimation(this, R.anim.fadein)
    val out = AnimationUtils.loadAnimation(this, R.anim.fadeout)    
    view_background.setFactory {
       val imageView = ImageView(this@MainActivity)
       imageView.scaleType = ImageView.ScaleType.CENTER_CROP
       imageView
   }
   ...
}

External method for changing the background:

private fun setBackgroundWithImage(activity: Activity, image: Int) {
    val backgroundView= activity.findViewById<ImageSwitcher>(R.id.view_background)
    backgroundView.setImageResource(image)
}

The view_background:

<ImageSwitcher
    android:id="@+id/view_background"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:adjustViewBounds="true"
    android:alpha="0.3"
    android:onClick="onTouchBackground"
    android:scaleType="centerCrop" />

This was working fine and the fade was happening correctly.

The Problem:

This is what I tried with Glide:

private fun setBackgroundWithImage(activity: Activity, url: String) {
    val backgroundView= activity.findViewById<ImageSwitcher>(R.id.view_background)
    Glide.with(activity)
            .asGif()
            .load(url)
            .into(backgroundView.nextView as ImageView)
    backgroundView.showNext()
}

However, this doesn't work, showing always an empty background. Why is this happening?

Zoe
  • 27,060
  • 21
  • 118
  • 148
justHelloWorld
  • 6,478
  • 8
  • 58
  • 138

0 Answers0