I have around 10 activities in an app and around more than hundred images. Now need to provide support for multiple screens of diff sizes and densities. If I need to create for small,large and xlarge sizes even though it will be customization of 30 more activities rest aside diff densities for a specific size :O Is there any way I can stretch the whole layout depending on the size and densities, I mean what is the best way to solve this problem. It must be a very common problem but I am missing something here. I read the android dev. screen support doc but still confused. Any ideas? Thanks for your help.
It's hard to give an answer specific to your project, but in general Android does a good job of this all by itself. All layouts will automatically scale if you haven't specified fixed dimensions (ie using px instead of dp). When it comes to fullscreen images (background and the like) it is best if you provide several resolutions (in the drawable-mdpi, drawable-hdpi etc) folders. You may also have to look at the scaleType for an ImageViews you may have.
Read through the official documentation on how to support multiple screen resolutions. It provides all the information you need and it goes into detail on how to provide different layouts not only for different screen resolutions, but also for different screen orientations and things like smallest width etc (for tablet specific layouts)
Related
I made a calculator app and used density independent pixels to create the layout, place the buttons and so on. Yet on a tablet emulator it doesnt display correctly, it only takes about 1/4 of the screen. On my phone(800x480) everything is ok. How can I adress this issue?
You'll need to provide additional layout folders for the different screen sizes so that the Android system doesn't use the same one by default, resulting in the behavior you've described.
This is accomplished by adding layout folders with size specifiers such as: small, medium, large and xlarge.
layout-small is an example.
So, to be clear, you're adding additional folders for the different supported screen sizes. You'll then add a layout of the same name to each folder you add. The system handles the headache.
You would then alter the layout to achieve the best results. Note that it is common practice, when dealing with larger screen sizes, to provide more content on a single screen as opposed to blowing everything up. If your app can benefit from that, it looks better than having obscenely large buttons stringing across the screen, IMHO.
For a complete run down, please refer to Android Documentation.
I designed my app for phone. If all I want for it on Tablet is just to scale up everything (i.e. bigger images, more distances), Is there a way to ensure this happen when doing my XML (or in the code)? Or should I create a different xml for xlarge screens?
I always come across the question and don't know the answer. Please don't refer me to the documentation of supporting multiple screens because I read it many time and it shows how you can customize for diff screen sized. In my case, I just simply everything scaled up keeping the same ration as the phone
Thank you
i'm an italian guy and i'm developing an android app for a course that i'm attending at Information and Communication Technologies university.
This is my question: following android philosophy, it is right to create 12 folders for different values of hight and width (in dpi) in android?
I mean:
values-ldpi
values-mdpi
values-hdpi
values-xhdpi
values-small-ldpi
...
...
...
values-xlarge-hdpi
values-xlarge-xhdpi
I can't use "match_parent" or "wrap_content" everywhere, so for some components i have to specify the size in dpi.
That is correct, but you can get a whole way by simply putting up your XML layouts smartly, using Fragments and thinking of a design that allows the use of some relative position descriptions.
Your solution is certainly the most exhaustive and thorough. It isn't necessarily "right" as you say though.
Ideally you would be able to create values/layouts/drawables for every possible combination of screen size/density. In the real world, it is more common to focus on a particular subset.
For example, you can have a look at the most commonly used screen densities here (updated periodically).
There are particular drawbacks to being exhaustive, including large .apk sizes if you are dealing with drawables, and as such you can scale back your approach and focus elsewhere, or release multiple .apk's for your application.
There is an in-depth article on Supporting Multiple Screens on Android here which is well worth a read.
There is not a generic rule that can work always.
In some cases you could have to use values-land, values-v14, values-large-land-v14, values-sw720dp....depends on the app you want to achieve.
Don't forget values-xxhdpi
I am into layout design for my app to address multiple screen sizes. I referred the following documentations:
Supporting Different Densities
Supporting Different Screen Sizes
Icon Design Guidelines and
Draw 9-patch
The more I read those documents, the more I became confused and convoluted. Although this might have been discussed here, I think I, at this point, need an expert advice.
What I found is that:
make one set of 9-patch images.
make adaptable layout and let Android stretch the 9-patch image for me.
Is my understanding correct?
Well, it's not that easy if you want to support most of the devices available; just one set of 9-patch images will not be enough, unless you use them only for background patterns.
You'll need at least one set of 9-patch images for each density folder, and together with a well-thought layout(maybe different for large and xlarge devices), and a good use of Fragments, you can manage to develop a nice looking app on most devices :)
Yes, that's correct. Adaptable layouts and 9-patch for backgrounds and simple images.
Note that if you have complex images maybe 9 patch are not well suited for it. Convert it to xhdpi, hdpi, mdpi and ldpi densities, and you're set.
Good look :)
I have developed an Application for android compatible devices mostly covered mobile phones, but when I am running it on Tab the screen size will get changed and all the content on the particular screen not behaving properly, As I have designed it keeping in mind that it should be compatible with mobile phones
Now, I just wanted to run my app on tab with the same screen size as it is showing on my mobile phone, without stretching of screen size.
What should I do to achieve it ??
Thanks
This isn't really a question that can be answered with a simple "set this style flag on your activity and you'll be on your way!" kind of answer. To get an app to scale properly across multiple screen sizes, you really need to start with the layout design itself. Android will try to keep your components the same size across different screen densities, but if you just leave it at that it still won't look very good because you'll have lots of empty or poorly utilized space.
The platform documentation and design guidelines go fairly in-depth into screen size compatibility and making a single app work and look good across all screens, large and small. In particular, I recommend reading the following articles:
Supporting Multiple Screens
Supporting Different Screen Sizes
Supporting Different Screen Densities
It'll take some work to make your app look and work great on tablets and phones (with just one APK) but if you want to make a good experience on a tablet without the hassle of maintaining two separate codebases, it's worth learning.
Pay particular attention to size qualifiers, which allow you to load different resources (drawables, layouts, etc) based on screen size (small, medium, large, x-large). That way you don't have to just blindly scale everything up on a tablet... if appropriate, you can tweak your layout on a tablet to make the experience more user-friendly.
Additionally, I recommend looking into Fragments, which allow for lots of flexibility in your UI across tablets and phones while not requiring you to have to write a bunch of code for differing layouts. For example, instead of having a newsreader that has two screens, one to display a list of articles and one to display article content, you can use Fragments to have a side-by-side, two-pane view of articles and content on tablets, while still having two separate screens on phones, which are more narrow. Fragments and FragmentActivities make this much easier to write and maintain.
You could set layouts width and height in pixels.
It probably isn't the only way but it's what comes to my mind right now.