Dmitri
Dmitri

Reputation: 2457

Android background image stretching

I have a problem with my Android app background image. It is large enough: 800 x 470 px, but the thing is - it is getting stretched to the screen dimensions, when I use it as a Layout background attribute (I use LinearLayout, by the way). I found a solution to use an ImageView (with centerCrop scaleType), but it crops the very very centre of the image, and I want to crop the LEFT part of it. Offset by X axis helps, but if I switch to horizontal layout - it looks like a crap. Is there any solution that would help me NOT to use two separate background images ? Or it is impossible.

Thank you very much for your answers. :)

Upvotes: 1

Views: 3516

Answers (1)

Ian Warwick
Ian Warwick

Reputation: 4784

Android devices come in many different screen sizes, so its best not to have a fixed size background.

You could use a 9-patch image and define areas in the image that should stretch, you can learn about this here http://developer.android.com/guide/developing/tools/draw9patch.html

Of course, using a 9-patch might compromise the background images design, so you would have to make adjustments to make it 9-patch friendly.

Hope that helps.

Upvotes: 1

Related Questions