简体   繁体   中英

Android non-repeating textured background

I have an iOS app that uses unique textured backgrounds (think of a game title screen or something) on each of the screens that I am trying to port to Android. On iOS they knew the resolutions and just designed the backgrounds around those. Obviously that isn't possible on Android.

What is the best way to put a textured/non-repeatable background into Android that works on various screen sizes and aspect ratios?

The solutions I have thought of so far are:

  1. Fit the shortest dimension and allow the image to go off the edge of the screen for the larger dimension
  2. Make the background image large and center it, then make it stretch out beyond the edges when the resolution is smaller than the image
  3. Stretch the image to just fit (this is ugly and I'd like to avoid it)
  4. Create a different version of the image for each resolution. (This seems way beyond the scope of what is possible for this project.)

As far as I can tell in Android, 1. and 2. aren't possible out of the box because background images set the size of the view to match their size (you can't tell it to just extend beyond the edges, please correct me if I am wrong).

What solutions would you use in this situation?

Create a different version of the image for each resolution.

As you're probably aware, Android can run on a wide variety of devices with varying resolutions and screen densities. To be fully compatible with all of them takes a bit of graphics work; you need resources for each possible screen density (and in this case, resolution).

For full details, see Supporting Multiple Screens in the Android developer documentation.

Unless something has gone seriously wrong in your development process, you should have the original files (eg .psd ) to work with when creating these resources.

  1. Use an (match_parent) ImageView to simulate back ground image. (By adjusting the scale type of imageview you can get the result of point 1,2) http://developer.android.com/reference/android/widget/ImageView.ScaleType.html

  2. Use 9-patch image. You can specify which part of your image can be stretched. For your case I suggest adding a small "margin" to your image, and make it stretchable using 9-patch. Only the margin will be stretched, maintaining the aspect ratio of your image. android developer 9-patch

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM