I need to develop an Android application and I am a starter to this environment. Actually, we need to port our existing application written for iPhone with Objective-C to Android. We are targeting four devices for now: Samsung S2, S3, Note and Note 2. The application completely consists of custom images in its buttons and backgrounds. As from my experiences in iOS development, we designed 320x480 and 640x960 backgrounds for non-retina and retina devices and the system selected the correct ones provided we give appropriate #2x suffixes. I am trying to understand the Android's way of handling this. I have read the [Supporting Multiple Screens] (http://developer.android.com/guide/practices/screens_support.html) document, but I am still confused on a few things.
As far as understand, there are size and density categories named as small,normal,large and xlarge and ldpi, mdpi, hdpi, xhdpi. We need to generate appropriate bitmap resources and place them under correct "drawable-X-Y" folders. This looks like an advanced version of the #2x notation in iOS. But I don't get exactly how we should prepare background images. For example Note1 and Note2 have resolutions of 449x718dp and 431x767dp respectively if I calculated correctly and therefore they both fall into normal size category. If we prepare a background image for Note1, its screen ratio won't be the same for Note2 and the background image will have to be resized. So, the system does not handle different sized devices which fall under the same size and pixel density category. So, what I do not get is how this system allows us to reuse the same background image for similar devices under the same size-density category. Should we prepare separate background images, say, for Note1 and Note2? If so, what is the meaning of this categorization, am I missing something?
We are targeting four devices for now: Samsung S2, S3, Note and Note 2.
Unless you are controlling the distribution of the app, and can somehow limit it to run on those devices, then at best those are sample devices. If, for example, you are planning on distributing your app via the Play Store, your app will wind up on many others, with a range of screen sizes, densities, and resolutions. While you can perhaps limit the size/density combinations via <compatible-screens> elements in your manifest, there are still going to be a range of resolutions.
So, what I do not get is how this system allows us to reuse the same background image for similar devices under the same size-density category. Should we prepare separate background images, say, for Note1 and Note2?
In the case where you can limit the distribution of your app to those four devices, if you want to use android.os.Build to sniff on the device and choose a different image based upon the device model, you are welcome to do so.
In the case where you are distributing the app to a wider audience, where your app could run on arbitrary devices, you have no practical means of determining, up front, what all possible resolutions might be used. Hence, you have no practical means of creating custom images for each possible resolution. In this case, you will need to rethink the approach of your app, learning from the techniques that millions of other developers of desktop and Web apps have used for dealing with arbitrary resolutions.
It is better to use dp for your control sizes and use 9-patch for Android apps. Android SDK can not handle this kind of detailed categorization. the hdpi/mdpi large/xlarge screen can help to an extent, but your case I think there is no easy way. If you absolutely need to do separate images for each device, then you may consider to do layouts like this:s2_layout_actvity.xml, s3_layout_activity.xml, and in each of them use corresponding images. And detect what device you have before you call the setContentView.
Related
As we all know that Google launch new feature of distributing android apk using android-app-bundle that has so many advantages.
So my question is, how my app will behave if I place all the images/resources in single folder like drawable-xxxhdpi. e.g. Lets say I have one application that uses 5 images. Instead of taking different sizes for different resolutions, I place all the images in single folder (drawable-xxxhdpi) assuming lets android handle it based on device resolution.
As we know that android-app-bundle generates different different apks based on resolutions, languages and so on.
So in that case what will happen to my app ? How APKs will be generated for different resolutions (Android itself re-scales images and generates bundle ?) What will happen to app, will it crash or working properly for smaller resolution devices ?
I know this is non- coding question but its technical question. I tried to search for this but not able to find exact answer of it.
I may help to others as well.
Your app will work the same as before: Play serves to a given device the files that the Android platform would have loaded if it had served the APK with all the files.
In other words, if an mdpi device would have loaded the resource res/drawable-xxxhdpi/icon.png, then that's what Play will serve to that device.
--
Also, slightly unrelated to your question, but note that there are some downsides to providing resources only in xxxhdpi (regardless of whether you publish an APK or an Android AppBundle):
The Android platform will have to rescale these images at runtime on lower resolution devices, thus taking some CPU time and making your app slightly slower.
Your app is bigger than it could be on lower resolution devices. If you provided also the same resource in mdpi, it would obviously be smaller, and that's what Play would serve to an mdpi device, thus making your app smaller for those devices.
Resource not found exception will be triggered in devices with lower resolutions
Good and very helpful question, I think your application will work fine on xxxhdpi devices but those devices which are mdpi or hdpi will face layout issues. I don't think so there would be any other issue than this.
I have say 30 images in my android app. And as per android's documents I should have images for all screen resolution i.e. I should have drawable, drawable-mdpi, drawble-hdpi etc.
Does this mean that I will end up having and asking the user to download 30*4=120 images, or does the android platform check before uploading and only uploads the images supported for that particular phone?
Is there any nice and easy way to handle these images?
Currently you need to include all those images, if you want your app to have nice UI on all screen sizes and resolutions. You can also choose to target your app only on specific screens, and declare that in the manifest. Users with screens that don't match your requirements will not see your app on the market then. However, this is probably not what you want.
As for the future, google knows about this problem and announced that it will support creating separate .apk for different kinds of devices, so in the future, this will be the way to go for apps with big sizes. Search google for "multiple apk support" for more info.
Those are for the on device images (app icons, menu item icons, splash screen image).
It sounds like you are having your users download some additional images themselves, so why don't you download only the images needed for their specific screen resolution. That way, you can even have better control over the quality of the images, as you can go by actual screen resolution rather than by hdpi, mdpi, or ldpi.
You could dynamically get android to create images for their device from a master image.
I don't think there's an alternative, there's no way to supply a different app to a user based on their device specs, other than API version.
I was looking at the source code of the open source Google IO App for android, and I relazied that they only have drawables in the "drawables-hdpi" (with only 2 exception out of 50 or so).
Reading the android guides and articles, I came to think that we need to support different screen sizes and resolution, but Google's IO app, which is supposed to reflect good GUI design patterns only has drawables for hdpi.
What is even more confusing to me is that it looks fine on my small low-dpi screen (SE Xperia X10 Mini).
Can someone please clarify my confusion.
This is a new answer because it cant be postet as comment due to its length... Android will take care of scaling. So it is not necessary to provide different screens if you just simple scale the images yourself. See this comment from Dianne Hackborn (Android framework engineer):
Sure, if you are actually generating different bitmaps for different densities, then you must be doing this because you want/need to carefully control their graphics. However my original point stands: if what you are doing is drawing your icons at one high resolution and then scaling those down automatically to generate lower dpi versions, it is well worth considering just letting the platform do the scaling for you.
Also keep in mind that for the new tvdpi density that is used on things like the Nexus 7, we strongly discourage developers generating their own bitmaps for it. Let the system take care of scaling those down (from the hdpi or higher density version you supply). This is what is happening for very nearly every single graphic you see on the stock software that comes with the Nexus 7. If it is good enough for what is shipping on the N7, it is probably good enough for you.
Source: https://groups.google.com/forum/?fromgroups#!topic/android-developers/-CMgbDIo0qA%5B1-25%5D
Android does a lot of work on its own in order to get stuff to look well on almost all screens.
Taken from: Supporting multiple screens
At run time, the platform provides
three types of support to your
application, to ensure the best
possible display on the current device
screen:
1) Pre-scaling of resources (such as
image assets)
2) Auto-scaling of pixel dimensions
and coordinates
3) Compatibility-mode display on
larger screen-sizes
Specifically, since that app only has hdpi images, it will downsize them to look well on a mdpi and ldpi screen.
The Google IO App was for the Google IO conference attendees. If you remember, all attendees received a HTC EVO at the conference that was pre-loaded with this app (in lieu of the traditional binder with maps and schedules). So since the EVO is a hdpi capable device, I'm guessing they didn't need to include icons that weren't hdpi.
As for why it looks good, blindstuff has that covered. They auto scale the icons down for smaller devices.
I have an Android app that I would like to display high quality images with. However there are many different screen sizes and ratios. I know there are filters to show apps in Market only for devices with small/medium/large screens.
If I put images of both sizes in 1 app it will double the size of the app, right?
Is it a good practice to make multiple versions for different screen sizes?
I would like to make 1 app in 3 versions for such devices:
medium screen mdpi
medium screen hdpi + large screen mdpi
large (tablets)
If it's possible to do it how can I specify them in manifests? Or is it somewhere in market?
Android has a built-in mechanism for having resources designed for different screen sizes and pixel densities. It's called resource directory qualifiers, and you can read all about it here.
For example, for small screen sizes, you could create a specific layout file and place it in the res/layout-small directory. For a larger screen, you could create a layout file with the same name and place it in the res/layout-large (or res/layout-xlarge) directory.
For pixel density, you could create a small version of your image resources and place them in the res/drawable-ldpi directory (lower pixel densities). And for higher pixel densities, you could create alternate versions and place them in the res/drawable-hdpi directory.
I'd encourage you to read the page on Supporting Multiple Screens, and let Android help you out with its built-in mechanisms. Creating three separate copies of your app is harder for you to maintain, and it confuses potential users (most of whom probably neither know nor care about "pixel densities"). What's to stop them from downloading the wrong version of your app, and getting a lousy experience because of it?
No one seems to be addressing the file size issue you're really asking about, so I'll try.
You should package your high quality images as a set of separate downloads, one for each type of device you plan to support. This makes your base app small, and ensures the end user's disk space is only filled by images it needs.
I've not done this myself, but hopefully the idea will send you on the right search path. I imagine you design the separate download as either resources on your own server, or another set of apps in the market (i.e. "MyApp Image Pack HDPI", "... MDPI", etc.).
As Donut mentions above android has excellent documentation for this here, here, here and here.
Note that all Manifest file changes and how to create one binary that will support different screen sizes, different densities AND different SDK's are at android website. But it requires careful planning and testing to do so.
The best way is to have ALL device configurations (listed here, including the Samsung Galaxy Tab simulater (large screen, hdpi) available here) in your development environment and test your app on them.
You have to create different .apk for each version and define this in your application's manifest file.use this link
http://developer.android.com/guide/practices/screens-distribution.html
How big is the smallest motorola android's screen, in pixels? I want to know what size I need to make my graphic without it being too distorted by the fill_parent.
Although this doesn't directly answer your question..
Android is the name of the operating system running on Android phones. Different phone models could have different resolutions and pixel densities. Therefore you have to be careful not to hardcode resolution values into your code. It might run well on one phone but poorly on another.
Check out these pages for details about supporting different screens:
http://developer.android.com/guide/practices/screens_support.html
http://developer.android.com/resources/dashboard/screens.html
It would be unwise to program for one screen size, especially if you plan on distributing your application later. You should design your application for as many screen sizes as possible.
Instead use nine-patch images and flexible layouts.
If you are designing an icon, the look at the android icon design guidelines and consider high, medium and low density screens. There are different resource folders for these too and android takes care of selecting the appropriate one for the current device.
motorola droid's display size is 480x854 px, according to specs, so it's rather non-standard