6.8.4. Overriding View Method onSizeChanged
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 ...
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.