Challenge: Efficient Thumbnail Load

In this chapter, you had to use a crude estimate of the size you should scale down to. This is not ideal, but it works and is quick to implement.

With the out-of-the-box APIs, you can use a tool called ViewTreeObserver, an object that you can get from any view in your Activity’s hierarchy:

    val observer = imageView.viewTreeObserver

You can register a variety of listeners on a ViewTreeObserver, including OnGlobalLayoutListener. This listener fires an event whenever a layout pass happens.

For this challenge, adjust your code so that it uses the dimensions of photoView when they are valid and waits until a layout pass before initially calling updatePhotoView().

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
44.222.146.114