0

How do I go about setting the background for a splash screen that does not stretch, and maintains a density-independent size? Here's a visual of what I'm trying to go for:

enter image description here

I have a large image file (1000x1000px) of the background. I want the background to maintain its density-independent size, with the excess just not visible, so that it will be displayed correctly on various screen sizes. I also want the center of the image anchored to the center of the screen. (the image above is just a mockup, the focal point should be at the center of the image)

How do I do this?

Renjith
  • 5,783
  • 9
  • 31
  • 42
  • 2
    http://stackoverflow.com/questions/5902230/how-to-implement-an-androidbackground-that-doesnt-stretch - Does this help? – Tiago Almeida Apr 04 '13 at 08:41
  • Hmm, but won't the ImageView have a maximum size of that of its Layout container? Can I get the ImageView to extend out past the Layout? – Michael Zimmerman Apr 04 '13 at 08:46
  • 1
    I belive that if you set your ImageView layout_width as wrap_content and height has wrap_content it will extend. However, as an alternative solution you can set the width and the height as 1000x1000px :) – Tiago Almeida Apr 04 '13 at 08:50
  • Posted the answer for future reference of anyone who tries to and find this. Hope that you used this anwser. Otherwise, let me know :). – Tiago Almeida Apr 04 '13 at 08:59
  • @TiagoAlmeida, this is what I'm getting: http://goo.gl/L8hmH – Michael Zimmerman Apr 04 '13 at 09:04
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/27544/discussion-between-tiago-almeida-and-michael-zimmerman) – Tiago Almeida Apr 04 '13 at 09:05

1 Answers1

1

You have a link here in stackoverflow that might help.

You can use an ImageView as your background (otherwise backgrounds of any view will just stretch).

And use it as the background of your ImageView. Your ImageView can then have the layout_width and the layout_height as wrap_content.

Then, set the ScaleType as android:scaleType="centerCrop".

Note that this ImageView has to be the first element of your layout. Otherwise it will just hide everything in your layout.

Community
  • 1
  • 1
Tiago Almeida
  • 14,081
  • 3
  • 67
  • 82
  • It's still not working for me. I even tried programmatically setting setMinimumHeight() and setMinimumWidth() on the ImageView object. Nothing. Looks just like this layout editor: goo.gl/L8hmH – Michael Zimmerman Apr 04 '13 at 09:11
  • Try to join the discussion I opened above and I can help you more properly. I don't have the androidSDK installed in this machine so this is the only way to help you out :/ – Tiago Almeida Apr 04 '13 at 09:14