Easily scale android application for smaller screen sizes - android

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

Related

Implementing Layouts According to Screen Size

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

Android User Interface Scaling

I have a project I am working on where the UI I have developed looks great on a 7" tablet, but the moment I try to use the app on a 10" tablet there is a lot of extra space to the right and bottom of my UI elements. Is there a way to scale UI elements to be bigger based on the size of the screen?
I need the UI to look exactly the same on every resolution possible. It should be noted that I am restricted to Eclipse and am programming on an older version of Android because the utilities I have been supplied with are older utilities.
Wish I could supply a screenshot, but I 100% cannot.
You can use different layouts for different screen sizes.
layout-sw600dp ( for 7 inch tablets)
layout-sw720dp ( for 10 inch tablets)
The system will automatically pick the layout per current device size. Just make sure to have the same layout name and id of the components in the layouts or it might cause exceptions if mismatch is found.
If you want completely different layouts for different sizes ( file names still have to be the same ), you can determine which kind of device it is, you can follow the description in the following's accepted answer.
Determine if the device is a smartphone or tablet?
Now using the above method, you can find appropriate views using IDs or whatever way you prefer without causing exception. I personally just change the dimensions of things and keep the ids same.

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 *

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'.

Categories

Resources