Trouble with implementing app for different screens on Android - android

I am about to publish my first app and I am extremely confused about making it look nice on different screens.
At first I thought mdpi/hdpi/etc. values (dimensions) folders would suffice when I saw that the screen was showing the exact same things on S4 Mini & S6 Edge, hdpi & xxxdpi respectively.
Well, how is this even possible when I haven't specified other than the main dimensions.xml file?
From what I understand from playing with the layout editor on different devices is that screen size matters more (?).
So far I have created a mdpi/hdpi/xhdpi/xxhdpi folder but it seems that that's far from enough.
What other folders should I make? Do I need many layout folders too?

I would use this scalable size unit library. It's really easy to use and it will automatically scale your widgets for various screen sizes.
Here's the link if you are interested: https://github.com/intuit/sdp

Related

How to create separate layouts for Nexus 5X and Nexus 6P?

Since the launch of Nexus 5X and Nexus 6P, I have noticed my layout designed previously looks relatively small on these new two devices. I tried creating multiple Layout resource folders but nothing seems to be working efficiently. After going through multiple tutorials and blogs, I am still struggling with this issue. Any kind of help or tutorial would be really appreciated.
Using multiple layouts is the correct way to solve Layout problem only. Besides, you also need adding suitable drawable resolutions and dimensions.
See more:
Make sure to use dp and sp as your scale.
Make sure if the correct layout folder is being picked by the mobile phone (see note below)
Resolution of image assets must be proportional to the dpi - check the Android icon resolution requirements and scale your image assets accordingly.
*To determine if the app does pick the layout folder you intend the app to pick - you could change the background for different layout folders and determine which one it picks *

Supporting different devices with different layout

I have doubt in making the layout for other deices I mean to support different devices of different resolutions. I have made an application and it is working well on hdpi devices and I tested on Samsung Galaxy grand which has 320dp-460dp and 480px-800px.
May application is looking awesome on this device. but when I run on other devices its gone bad. SO I am suggested to make the folder like layout-large, layout-xlarge and layout-xxlarge but there is a lot of difference in this link and this link
So this makes me confuse , with which name I have to make the layout folders to support all devices ?? please tell me
and also tell me I have some hard coded values in my layout such as left margin 13 dp to make my design look perfect on hdpi device should I make it more in other xhdpi devices ???
and also which devices comes in layout-large folder and so on please answer my both confusion , thanks in advance
I use Google's code as an example of how to do stuff. The docs on "Supporting multiple screen" is a bit old and outdated. The best way to keep up with the current conventions is to follow other's codes.
Here is the source code for the Calendar app. Yes, there a lot of different folders for layouts/drawable/values but you have to consider the fact that there are a lot of devices with varying sizes and pixel densities.
Also, why do you want to make many folders for layout? You make a few layouts and let the values and drawables do the rest of the work. Hope it's helpful.
IF you are interested in knowing which device falls under which folder, then check this figure from the Official Android Guide:
Of course you need to know the actual size or density of the physical device

How to create layouts properly (Android)

i´m pretty new to android development and creating different layouts for each resolution wasn´t really that easy for me.
So, I was able to optimize my app for most devices (in eclipse), but i´m still having some problems here and there:
do I really have to copy the same images with different resolutions for each device-resolution into the respective folder? I´m currently using the hdpi, large-hdpi, mdpi and xdpi folders...
isnt it possible to use one drawable-folder and just scale the images down?
is there an extra drawable-folder for those 5.1in (WVGA)/5.4in (FWVGA) devices? In eclipse they´re labeled with mdpi, but these devices are using the large-hdpi folder and those images are too big, but perfect for i.e. nexus 7.
i´m also using 4 different layout-folders (layout-sw360dp, sw480dp, sw600dp & sw720dp). Is that a proper way to create a layout for each device-group?
Hopefully someone is able to help me with this.
Thanks in advance!
1) Yes you have to copy the images with different resolutions for each device resolution into respective folder. Because if you don't do that you will have unexpected results on different screen sized i.e. misplaced controls and layout will not be proper.
2) If you scale the images then they will get stretched or squeezed and you will not get proper result on the screen.
3) Folders sometimes behave differently on different devices. Sometimes they don't use the folders they are intended to use.
4) Yeah! as recommended in the documentation it is a good practice to use different folder as you can't be sure of the screen sizes in android.

Large screens layout not as expected

I developed and application and uploaded all the images in the respective drawable folders (different pixels for different desnities).
Now I am confused when it comes to layout. If I used the layout editor with 4.1 inc (thats considered Med screen I guess?) everything looks great.
Now when I use the editor with 10.1 inch which is the tablet, then I see icons very small and the text is small. I have not run the emulator yet.
So I am wondering:
1- why would the text be small although I didn't specify text size? Shouldnt scalle appropriately? or should I give it a specific size for bigger layouts?
2- Why the icons are small given that I provided the different drawables? I thought it would scale up accordingly.
Please don't give me the supporting multiple screens link in android as an answer, as I already went through it and still no luck with above. I need your personal advice as I think I am missing something here
Thank you so much in advance
Android support for different screens is a little tricky. That's because you can have large, small, medium and xlarge screens, plus high, medium and low density ones. There are a dozen possibilities (xlarge low density, small high density) and not a single resolution is defined. So you must know the principles which the API is designed upon and must define your layout thinking about the role the widget has inside your UI. You also must bear in mind that your layout won't be pixel perfect on 100% of devices, so your aim should be being usable on all possible devices.
In your specific case it seems that either you don't manage to specify the correct resources, or the system doesn't pick up the right ones for you, but I must remark that it doesn't make sense on Android to talk about big, small and scale: you should design your layout with a (good) webdeveloper mindset, who daily deals with tons of different displays, resolutions, physical sizes and even devices.
I also suggest not using the graphical builder if you are new to Android, because you really need to know how Android lays out components, otherwise you will come back to SO very often :)
If you do not specify the text size in your layout file Android will take the default value, which is most likely in DIP (density independent pixel) therefore it will be the same physical size on any devices. That should explain why the text looks so small on your 10 inch tablet.
What I would do in this case is have 3 layouts for each activities and specify the text size for larger devices (given you already like the look on phones) and put them in this folder scheme :
res/layout/layout.xml // phones
res/layout-sw600dp/layout.xml // 7” tablets
res/layout-sw720dp/layout.xml // 10” tablets
Information above was taken in this article. I have this applied in my current personal project and so far it works like a charm.
Secondly, as far as icons go, I'm no drawable expert but if you provided the same file in each folder (like I think you did from what I understand in your question), it will not make it scale. You'll have to create 4 difference icons, one for each possible pixel density.
Information about icon sizes can be found on this page.
Hope this is of some help to you.
My experience with the Android device zoo drew me to the sad conclusion that the built-in screen size/layout facility is useless. Cases in point, straight from support:
a 10 inch tablet with Android 2.2. Screen size xlarge is not supported by Android 2.2
Kindle Fire, which is 7 inch and claims it's xlarge.
I ended up putting all three layouts (med/large/xlarge) into layout, loading one based on run-time density and resolution, and providing an option for user to force a specific layout.
Just sayin'.

Easily scale android application for smaller screen sizes

Right now I have an application I built that is built for android 10.1 inch screens (tablet) and I would like to to be able to be scaled so that it work on the kindle fire (7 inch screen). What would the easiest way to do this be?
Edit:
So I've taken the advise that the majority of the people in this tread have given and replaced all of the absolute layouts with relative layouts and I am using margins left,right,top,bottom, to place them, but still the button images are too large and they are misplaced, how can i do this so it works correctly?
There are some design criterias for developing android applications to make them work in different configurations like screen size:
use different layouts for different configurations
use fill_parent and wrap content properties in layouts
do not give hard coded pixel values
do not use absolute layout
provide different drawables for different configurations
for more look here: http://developer.android.com/guide/practices/screens_support.html
Following the best practices guidelines is always good but sometimes you simple need a whole new layout for different screen sizes. Android allows you to create different layouts files for different screen sizes. To do this you can create a new folder under 'res' called 'layout-large' or 'layout-large-land' for landscape. The same is also true for 'layout-xlarge' and 'layout-xlarge-land'. You can just add another xml layout file in these directories with the same names and same ids and android will automatically pick the right one based on the users screen.
http://developer.android.com/guide/practices/screens_support.html
Honestly, it depends on your application. If you built it so that it would work with tablets and you didn't specify non-percentages for your widths and heights, it will probably automatically scale to the proper size on the Kindle Fire.
Honestly, get a test device (or emulate the size using the Android Emulator) and see what happens. Very likely, if you followed proper design patterns, the app will Just Work (TM) on the Kindle Fire.
If it doesn't, you might want to take a look at how you're specifying the sizes of your elements. Using Pixels or any other type of pixel-based numeric measurement will do some strange things to your UI. Instead of widths and heights, use paddings and margins defined with density independent pixels. This will help your app scale properly.
I recently wrote an app testing it only on mobile phones, and was pleasantly surprised when I purchased a tablet, and the app scaled up perfectly - with no warning from Android about different ways to scale it.
Realy easy, but not recommend because it can pixialize images, is Enabling Screen Compatibility Mode.
Try adding this:
<supports-screens android:compatibleWidthLimitDp="320" />
OR this:
<supports-screens android:largestWidthLimitDp="320" />
to your AndroidManifest.xml.
To understand whats happening check here:
http://developer.android.com/guide/practices/screen-compat-mode.html#Enable

Categories

Resources