Book Image

Mastering Android Game Development

By : Raul Portales
Book Image

Mastering Android Game Development

By: Raul Portales

Overview of this book

Table of Contents (18 chapters)
Mastering Android Game Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
API Levels for Android Versions
Index

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 uniformly (maintaining the image's aspect ratio) so that both dimensions of the image (width and height) will be equal to or larger than the corresponding dimension of the View.

We will add an ImageView at the beginning of fragment_main_menu.xml...