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. ViewTreeObserver is an object that you can get from any view in your Activity’s hierarchy:

V​i​e​w​T​r​e​e​O​b​s​e​r​v​e​r​ ​o​b​s​e​r​v​e​r​ ​=​ ​m​I​m​a​g​e​V​i​e​w​.​g​e​t​V​i​e​w​T​r​e​e​O​b​s​e​r​v​e​r​(​)​;​

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 mPhotoView when they are valid, and waits ...

Get Android Programming: The Big Nerd Ranch Guide, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.