January 2014
Intermediate to advanced
736 pages
70h 43m
English
Figure 6.10 overrides class View’s onSizeChanged method, which is called whenever the View’s size changes, including when the View is first added to the View hierarchy as the layout is inflated. This app always displays in portrait mode, so onSizeChanged is called only once when the activity’s onCreate method inflates the GUI. The method receives the View’s new width and height and its old width and height—when this method is called the first time, the old width and height are 0. The calculations performed here scale the game’s on-screen elements based on the device’s pixel width and height. We arrived at our scaling factors via trial and error, choosing values that made the game elements look nice ...
Read now
Unlock full access