O'Reilly logo

Mastering Android Game Development by Raul Portales

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required