Overridden View Method onSizeChanged

The DoodleView’s size is not determined until it’s inflated and added to the MainActivity’s View hierarchy; therefore, we can’t determine the size of the drawing Bitmap in onCreate. So, we override View method onSizeChanged (Fig. 7.23), which is called when the DoodleView’s size changes—e.g., when it’s added to an Activity’s View hierarchy or when the user rotates the device. In this app, onSizeChanged is called only when the DoodleView is added to the Doodlz Activity’s View hierarchy, because the app always displays in portrait on phones and small tablets, and in landscape on large tablets.

64      // Method onSizeChanged creates Bitmap and Canvas after app displays65      @Override ...

Get Android™ How to Program, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.