Implementing Layouts According to Screen Size - android

I'm wondering if it's possible to use different layouts based on a phone's screen size (not tablets, watches, etc.). I've already taken a look at this article, but don't seem to be having any success implementing what it suggests. Just for context, I'm using a ConstraintLayout for all of my layouts. I originally designed my UI using a Pixel 3 XL, and when I try to run my application on any other device, the UI looks distorted, its elements aren't anywhere they should be, and everything is just awful.
How would I go about making and assigning layouts for each screen size? Is there something else I could do instead?

Google recommend to create different res/layout directory for specific pixels, such as res/layout-1024x720,res/layout-1280x720,res/layout-1920x1080 etc..

#Inso is right, you can just save different versions of your resourses in different versions of your res/ subfolders (like layout-1280x720 or drawable-1920x1080). This not only applies to layout files but also to drawables and any other resource directory and you can create different versions not only by screen resolution but also by device API screen size and others.
I recommend you read the following documentation that explains all that is possible.
It might also be that you just chose the wrong layout type for your app. you should check the available documentation on layout types (there is a bunch out there) and see if maybe ConstraintLayout may have been the wrong pick.
I also recommend having a set of different virtual devices (from the emulator) having different screen sizes and running different APIs so you can test every now and them how your app performs under differnet conditions

Related

Trouble with implementing app for different screens on 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

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 *

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

How my android app will run on multiple screen resolution devices?

I have developed an android application and run it on an HVGA emulator. It's running successfully on any HVGA device i.e. mdpi. But if I try to run on small screen resolution devices i.e QVGA then my buttons are looking as if they go down and dont fit onto the small screen...
So how can I run my android application on multiple screen resolution successfully?
follow these instructions
create a folder in yourAppFolder/res/ named layout-small (*more on this subject later)
insert in this folder all your xml layout items that need special treatment for a small screen (it is not necessary to copy all of "normal" layout files, but you can if you wish)
change the files in this layout as needed
What happens with this approach:
if the device has a non-small screen, the default layout (the one in "layout" folder) will be loaded and used, otherwise if the screen is in "small" category the files in "layout-small" will be used instead (only if one with the same name is available, otherwise the one in "layout" will be used
*About folder naming: that policy was the old one supported by android. Nowadays there is another one, more precise but more complex too (example: specify minimum necessary width). Anyway, this is still supported, just note that eclipse may suggest you some alternatives. Currently, i am still developing with the old naming policy.
I think it is better to design your layout for every screen size and resolutions. It is easy in android. Copy your layout from "layout" folder of resources and paste it in the "layout-land", "layout-xlarge", "layout-xlarge-land" and ... folders and change those settings you need in them.
you can check this link:
In the UI builder (part of the Eclipse plugin), you can build your interfaces for multiple screen sizes and resolutions. To make different layouts for different resolutions, simply follow these instructions to build alternate layouts:
http://developer.android.com/guide/practices/screens_support.html#support

Android muliple screen support?

I have to design an application which to support under three resolution. for that i use the code in manifest
and also create three folder layout , layout-large, layout-small for supporting three resolution, correspondingly i put the different resolution of image in drawable-hdpi ,drawable-ldpi ,drawable-mdpi , but whenever i run the app in different resolution it going to take low resolution image instead of different resolution i use.
I don`t know where i made the mistake, whether i have to add some code in layout xml or not. I also search the android developer forum and i do the application design as they insist.
Any one suggest some idea to achieve this.Thanks
There are two things you could check: have you set the minimum SDK version of your app to use version 4 (Android 1.6) support for this started?
Secondly, the layout-large and layout-small folders are designed for different sized screens (think tablet vs phone), and not resolution. If you're changing the resolution (DPI) of the device, you'll need to use layout-hdpi, layout-ldpi etc.
Further, if it's only the images you're changing, you should be placing the different images in drawable-hdpi, drawable-ldpi etc, and not layout-xxxx. If on a supported device, Android will pick the image from the correct folder, so you'll only have one layout folder (or 2 if you use layout-land)
Some (or all :S) of these points are covered in this link, to another question on StackOverflow. Try to use the search function before asking a question. Also, you'll find people are more receptive to providing answers to users with higher accept percentages.
Android - layout-large folder is been ignored
Edit: for multiple screen support, also look at Fragments to better organise and fit your content for both large and small screen devices (dev.Android, worked example)

Categories

Resources