1

In my app I want to have a Screen in which the background is an image. That image will be stored in drawable, and I'm aware that I'll need to store versions of the same image but different sizes in the other drawable folders in order to support varying screen sizes/densities.

I found this information:

ldpi: Low-density screens; approximately 120dpi.
mdpi: Medium-density (on traditional HVGA) screens; approximately 160dpi.
hdpi: High-density screens; approximately 240dpi.
xhdpi: Extra high-density screens; approximately 320dpi. Added in API Level 8

My question though, is how do I know what size my image should be for each respective folder in pixels? The screen in which this image will be the background can only be viewed in portrait mode, so I'm wondering about sizes in respect to portrait layout.

user1513171
  • 1,700
  • 6
  • 27
  • 49
  • There's no practical need for ldpi assets anymore, but in any case, the proportions to use for scaling your assets is as follows -- ldpi : mdpi : hdpi : xhdpi : xxhdpi : xxxhdpi :: 3 : 4 : 6 : 8 : 12 : 16 – Karakuri Mar 28 '14 at 18:16
  • 1
    This has been answered here: [http://stackoverflow.com/questions/12768128/android-launcher-icon-size][1] [1]: http://stackoverflow.com/questions/12768128/android-launcher-icon-size – Ankhwatcher Mar 28 '14 at 18:19
  • And the scale factor is as follows: ldpi, mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi => 0.75, 1.0, 1.5, 2.0, 3.0, 4.0 – Phantômaxx Mar 28 '14 at 18:19
  • @Ankhwatcher, that is talking about launch icons, would it be the same for full-screen background images? I assume yes. – user1513171 Mar 28 '14 at 18:23
  • 1
    You cannot have a "full-screen background image" in general, any more than you can have one in a Web browser. Device screens, like browser windows, can have arbitrary resolutions. You will first need to determine your strategy for dealing with that (e.g., layer a background image on top of a solid full-screen background, with the image designed to blend into that background). Then you will need to factor in screen density. – CommonsWare Mar 28 '14 at 18:28
  • @Karakuri: 9.1% of Android devices are `-ldpi` as of [the current Android device dashboard](https://developer.android.com/about/dashboards/index.html). Depending upon your distribution channels, that may understate how many `-ldpi` devices there are, as some low-end devices skip the Play Store and therefore will not show up in Google's dashboard. Now, it may be that scaling from `-mdpi` will suffice in many cases, particularly for smaller artwork. I just don't want readers to think that `-ldpi` devices do not exist. – CommonsWare Mar 28 '14 at 18:30
  • Use this http://android-ui-utils.googlecode.com/hg/asset-studio/dist/icons-launcher.html#foreground.space.trim=1&foreground.space.pad=0&foreColor=33b5e5%2C0&crop=0&backgroundShape=bevel&backColor=ffffff%2C100 – petey Mar 28 '14 at 18:49

1 Answers1

0

Sorry User, I didn't read your whole question the first time.

If you're setting a background you can use a large image and create a scaled bitmap from it.

You'll want to use a method to measure the screen size to determine what you should scale your bitmap down to. for example:

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
metrics.heightPixels;
metrics.widthPixels;

Then scale the bitmap:

Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.welcome_background);
int nh = (int) (bm.getHeight() * (512.0 / bm.getWidth()));
Bitmap scaled = Bitmap.createScaledBitmap(bm, 512, nh, true);
BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), scaled);
welcomeScreen.setBackgroundDrawable(bitmapDrawable);

(This code doesn't scale to display size it just scales to a width of 512 px, but it should serve as an example)

Ankhwatcher
  • 400
  • 6
  • 18