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 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.