How can I provide Bitmaps for the full Android screen resolution? - android

Simple question actually and I have spent hours searching for an answer.
What is the best way to provide bitmap resources that fill the full screen? For instance for a full app background or something.
Currently I place all my images in drawable-nodpi in a medium resolution and obviously need a lot of custom scaling. I do need images the fill the full, or the half or a third of the screen width. What is the best way?
Michael Ellen states ( https://stackoverflow.com/a/6938345/1162415 ) that e.g. drawable-ldpi has 240 px screen width. While I would love this to be true I do not think so. Table 3 at http://developer.android.com/guide/practices/screens_support.html#testing clearly says that ldpi might result in actual px resoluation width of 240, 480 or 600.
Should I build the app with drawable-*dpi fixed for screen sizes, something like drawable-ldpi-small and so on? We do make use of 78 cards ( https://play.google.com/store/apps/details?id=com.pinkwerther.tarot if you are interested) which should be displayed almost full screen. That makes a hell of an overall app size. Either that or a hell of a lot of different apk files.

Now there is one solution I am currently thinking of that might be suitable. Namely to provide kind of low resolution default images and have the apk with an expansion file ( http://developer.android.com/guide/google/play/expansion-files.html ) of really high resolution images which get scaled and stored on first use. Before I dive into this possibility I just want to make sure there is no simpler solution... So please feel free to hint me to the hidden places I happen not to be aware of!

Related

Android layouts - images for the different screen resolutions and the same density

I want to show some images on the background that is also image. Say my background image contains an empty squares, and I want to show an apple image that must appear exactly in one of that squares.
I have a problems with the apple sizes, as the background scales and fits the screen, but apple image stays the same for the different resolution and the same density devices.
Say I have two ldpi devices with 240x320 and 480x800 resolutions. When I keep my drawable aple file in the drawable-ldpi folder, and use wrap_content for height and width (or fixed dp values) those 2 devices draw the apple with the same size, like it is described in the documentation.
The LinearLayout works slow when I stack them.
Using RelaytiveLayout I must programmatically resize the images which is also "not so good" solution I guess.
I've found a solution here https://github.com/intuit/sdp that maps the dp-s.
They set dimen-s for values-sw300dp to be
<dimen name="_10sdp">10.00dp</dimen>
and for values-sw480dp to be
<dimen name="_10sdp">16.00dp</dimen>
and so on for the different cases ...
So when I set the with of the apple to be _10sdp it means different dp-s for my 2 devices with the same density and solves my problem. Is it a good solution as it seems to be for me?
Is there any other easy ways?
This is indeed the recommended solution as you could see in the iosched github repository which is a generally good source of knowing whether something is a desired common practice at least according to Google since i know they spend a lot of time to create this code to reflect the best practices and obtain the new APIs
Your solution seems good, just as common solution, would be good to use folders described in documentation.
For your case, as easier solution I would suggest to not use an apple image separately and place it in background's square. You can have an image: apple in square, and place it on background wherever you want. An apple will always be in a square and you can avoid tiresome process of creating dimens for each configuration.

Generate Android images that are not icon sized

I have a set of 4 images I plan to display at the first launch of my app inside of a ViewPager. Each of them is 1MB, so that's 4MB total
I want these images to be shown for any density screen.
Where should I place these images?
In which size?
Will duplication increase the size of my app?
Maybe a more efficient way to do it? (one location for these drawables)
The closest I've found is http://romannurik.github.io/AndroidAssetStudio/ but it's only for icons
Thanks!
Q1.2. Location: /res/drawable. You can have many version of those images and place them in different folder: drawable-hdpi, drawable-ldpi... For better result, please read http://developer.android.com/guide/practices/screens_support.html
Q3. Duplication will definitely increase the size of your app. But common users will possibly ignore its size is not ridiculously big.
Q4. You can store only one image for every screen size, but you need more coding work to scale the drawable to fit the screen of different device. For better result please read: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html

Android layout multiple screen

Sorry but i cant understand how i can draw a right picture for the right android phone size.
I readed the android documentation, and they say for i just think in screen size and density and not in resolution, so what size should have my picture?
For example,if i have a phone with size 1000x400(stupid example),and want a button(40x40) that will be in middle,what size should i do?? 40x40?? But in documention they say for dont look for resolution :\
Im confuse...
ps: The documention link Android multiple screens
Basically you'll have to realize that although resolution, screen size and screen density are separate attributes, they are still somewhat related. If your button is 40x40 as you mentioned, and that's the size you find looks good in the center on a hdpi(high density) device, you will have to scale it so that it fits accordingly on mdpi(medium density) and xhdpi(extra high density) devices. What I like to do is use PhotoShop or another graphical editor and resize my assets so that they fit on whatever density devices I'm trying to target. I make sure to always use *WRAP_CONTENT* for my height and width attributes and never fixed values.
Also, if you do not include these scaled alternatives in your res/drawable folders..you're basically saying that you're relying on the system to scale them for you, which can be a gamble. So I always go with resizing my assets so that I include a version for all densities. The link you posed explains everything pretty well

Android screen resoulution problem

I'm writing a game for Android and can now test it on a second device, the Nexus 1. The game uses fix pixel-values, just using bigger cutouts of the background for high-res devices. So I thought there would be no problems. Somehow, however, the nexus 1 is making a specific image bigger than it should be (261*66 instead of 174*44). The picture itself as a resource is 174*44, so it's being stretched. Why? What can I do against it?
Edit:
Spritesheet = BitmapFactory.decodeResource(res,
R.drawable.bird_spritesheet);
Is the used code.
Edit 2:
Is there no way to tell the software to just use the size the picture is? I don't want to bloat my software by adding multiple pictures (/drawable-hdpi/ answer).
The pictures are supposed to be smaller on bigger screens.
what drawables folder to you have the picture in? If you put a copy of it in drawables-hdpi I think it will show up real size. It is really better to set things up in such as way that the final size in pixels it ends up is unimportant. Using pixels values is going to ensure that your app looks wrong on at least some of the screen sizes out there.
Because Android runs on multiple screen sizes and you use device independent pixels (DIPs), images get scaled to ensure they look the same on all devices. To avoid this, you can provide alternative resources for high density screens (in your case) and for low density screens.
More info about screens here

Bitmap scaling to fit different screen size/density

I do not really understand all those things about pixel density and device independant pixels and I want to know if I should worry about this.
More specifically, here is how my application work right now:
For the “layout screens”, I’m using RelativeLayout or LinearLayout and I never use pixels or dp, so I guess that this will look good on every device
For the main game screen, there is only a SurfaceView on the screen. With the values given by onSurfaceCreated() (pixels or dp? I don’t know), I compute the size and position of every element of the game, then I load the Bitmaps (with BitmapFactory.decodeResource() and then Bitmap.createScaledBitmap()) and put them on the screen with drawBitmap()
I tested on my phone (480 × 800 hdpi) and on the emulator (240 × 320 mdpi), and both looks good.
My questions are:
Is this the right thing to do? I do not understand how (and why) I could use the fact that some devices are hdpi and others are mdpi.
Should I provide different bitmaps for different screen densities, and why? (right now I have everything in res/drawable-hdpi)
What size should my .png have? Can I create them much bigger (2 ×) than their expected size, in order to be sure that this will not look blur or aliased?
My knowledge about this is limited, as i never developed games.. as i supposed you are doing.
Is this the right thing to do? I do
not understand how (and why) I could
use the fact that some devices are
hdpi and others are mdpi.
With this information you can load different images automatically. You can you the directories:
drawable-hdpi
drawables-mdpi
...
Should I provide different bitmaps for
different screen densities, and why?
(right now I have everything in
res/drawable-hdpi)
If you have all in hdpi then the images will be shrinked i think, to be smaller due to the lack of specific images o that scale. Providing the images will give you more control over the final product and it will spend less processing.
What size should my .png have? Can I
create them much bigger (2 ×) than
their expected size, in order to be
sure that this will not look blur or
aliased?
I think they can be exactly the size needed. But as i said above.. not much experience.

Categories

Resources