Working with backgrounds

Something that makes the game look bad is the plain white background we have at the moment. While we could set a background for the activity, this is not the best solution because background images are set to scale to fit, and that cannot be changed. When using a background image it will expand to cover all the view.

Note

The attribute android:background will stretch the image to make it fit in the view.

We do not want our background image to be stretched in one dimension. We want it to scale uniformly on both axes.

This can be improved with the use of a 9-patch as the background image, but in our case we will just use an ImageView that covers all the layout with scaleType set to centerCrop. This parameter does scale the image ...

Get Android Game Programming: A Developer’s Guide 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.