Question - Efficient Thumbnail Load

I didn’t get too far with the ViewTreeObserver. I mainly couldn’t figure out where to add it. And also got scared off a little regarding comments found while Googling it about memory leaks with lambdas. The solutions got into some Kotlin stuff that I don’t understand well yet. This in particular got me all kinda confused.

Anyhow, why wouldn’t it just make sense to do something like this? It seems to work and it seems like this shouldn’t be very costly performance wise. Am I missing something in this thinking? Maybe it wouldn’t get called in all situations? Maybe it makes us scale the image more often than we need to?

    private fun updatePhotoView() {
        val W = photoView.getWidth()
        val H = photoView.getHeight()
        Log.d(TAG, "photoView size $W x $H")

        if (W != 0 && H != 0 && photoFile.exists()) {
            val bitmap = getScaledBitmap(photoFile.path, W, H)
            photoView.setImageBitmap(bitmap)
        } else {
            photoView.setImageDrawable(null)
        }
    }

Yeap, same here here trying to figure out where to put it. Its quite confusing but I still put mine in onStart()

1 Like