How do I Update layouts for long and notlong resource qualifiers? - android

I noticed that although my drawable resources are being scaled down properly by android, the bottom of the layouts are getting chopped off on smaller screens(I assume notlong screens, as my testing device is a Droid which I believe is long, right?)
Should I be updating the layout files and putting them in a res/layout-notlong folder or something like that? Or should Android be handling this differently?

You rarely need to use -long and -notlong. You should be designing your layouts with layout managers that resize themselves to adjust to the screen size.

Related

Combining screen height with different resolution layout files?

I set up my Android application to support different screen resolutions (ldpi, mdpi, hdpi, xhdpi, ...) and that seems to be working as it should. Different screen heights on the other hand are not scaling correctly: I optimized my design to fit on the small screens (of the default Android Studio emulators) which means that there is a lot of empty space on longer devices. Is there any way to combine screen resolutions (xhdpi, ...) with screen lenght (long, ...)? If this is not possible at all I would really appreciate alternative methods of layout scaling in order to fix my problem. I currently use dp and RelativeLayouts only.
Thanks in advance.
RL in the picture below represents RelativeLayouts.
I would suggest using multiple nested linear layouts while specifying layout weights to scale components on all kinds of displays (see this guide for example). Tip: You can use empty views to create dynamic spaces.
Also in some cases it is useful to specify portrait and landscape layouts separately (see this guide) although then you have to manage some duplicate code.

Is there a function in Android Studio to automatically adjust the layout to the display size?

I'm in the process of creating a small questionnaire. Although all views are constrained, the individual text views overlap or slide to the edge.
So far I have only created the design for the layout and have not yet linked any functions with anything. When I display the layout on a larger display, everything is shown as it should be.
Can someone help me and tell me how I can design my layout so that it automatically adjusts to the display size?
I'm really new about programming in Android and don't know all the backgrounds I may have disregarded.
I tried to use the AutoSizeMaxText fuction but I'm not sure if I used it the right way.
As far as I know there is no such thing as an automatic function to support different screen sizes.
What you can do:
Use constraintLayout
Use match_parent and wrap_content instead of hard-coded sizes in your xml
Create different layouts for almost every (if not every) screen resolution:
ldpi, mdpi, hdpi, xhdpi, xxhdpi
Use stretchable nine-patch bitmaps for image resources.
Consider using fragments and double-pane structure for large devices
You may want to chek this library: https://github.com/intuit/sdp
and this one for text size: https://github.com/intuit/ssp
Don't forget to test it in as many devices with different resolutions and pixel density as you can.
You can check the official documentation for this issue: Android developers: Support different screen sizes

Is it necessary to create "small, normal, large and xlarge android xml layouts" folders if i want my application to run of all Android devices

I am developing an Android Application that supports all kind of Android devices like mobiles and tablets. But it's time consuming to create multiple folders (small, normal, large and xlarge android xml layouts) to support all the Android devices. Is there any way to build an android app that runs on all android devices without creating these folders:small, normal, large, xlarge etc?
You only need to create unique layouts (ie. *layout_mdpi* ) if you want something unique for that particular screen size.
If you want to use the same layout on all different screen sizes, you will only need to create a single layout (in the layout folder).
Only if you want to customize a particular layout would you need a new FOLDER in layouts (named: layout_mdpi) in that folder you would have multiple copies of customized layout with same name (ex. my_layout.xml)
To clearly answer your question - you will only need the layout folder and no other ones in your casel
Ex.
res\layout\my_layout.xml // this folder is all you need if this layout will work on all screen sizes
res\layout_mdpi\my_layout.xml // you ONLY need this if you are presenting something unique on this screen size.
In Android we need to maintain different folders for the layouts with different resolution reason behind it is the use or the resolution of the Android Device on which the application gonna execute.
small Resources for small size screens.
normal Resources for normal size screens. (This is the baseline size.)
large Resources for large size screens.
xlarge Resources for extra large size screens.
Android OS select the specific layout it self by checking the compatible device and its resolution.
So, better to create folders to support in multiple screens
For More Info refer this
Is there any way to build an android app that runs on all android devices without creating these folders:small, normal, large, xlarge etc
Consider this, you have a button (with match_parent) that stretches full width of a screen in portrait mode of a 4 inch phone, that's fine it looks alright, but then that same layout on a 10 inch tablet in portrait is now 3-4inch wide, that's not great looking.
"So what" you say, make it wrap content, okay then so the button now only fills up part of the width on phone, still looks okay but then on a tablet you have huge amount of space now either side of the button, maybe that's looks okay, maybe not.
Maybe same button on a smaller screen takes up too much space?
Now apply the above to every single layout element in your app.
Do you think it'll look good, using the same layout, do you think your users will be okay with an app that was so little care to its UI and UX?
SO, in conclusion, yeah it's possible to only use one eg normal, for all devices but it'll probably look terrible on most of them.

Android: support multiple screens

I am trying to make a application in Android. I want that it should be able to run on multiple phones of different screen sizes, so i studied support multiple screen on developers and according to that i have to create 3 different xml files for supporting three different screen sizes and also 3 different types of images for each type of xml file. But on a blog i get the idea of doing this by using current screen size method. So i am confused what i should do. means which is optimized and performance increasing way. And which one will be more perfect for supporting all types of screen(except extra large screens)
Defining height, width and other parameters in the XML file is the better option rather than on run time.
Because XML files works as metadata (data carrier) to the activity and avoids alot of confusion when onCreate mothode in called.
Plus, create different folders for image quality (hdpi,xhdpi,ndpi,ldpi)
7 inch device use mhpi
10 inch devices use hdpi and xhdpi
While NEXUS tabs use hdpi and xhdpi irrespective of their size.
Mobiles use ldpi and ndpi.
Beauty lies here is that android device automatically pick-p the suitable content when found, i.e layout and image.
If not found it would first search other Layout folders,e.g a layout not found in x-large folder then it will search in large,then medium, small, which one of them suits the best ,(if a layout is not found in its respective folder).
Nexus will create alot of trouble for you.
To check how your layout would look on different devices, try using the options, which tells you how it would look on that device with those height width, present in the Graphical (view of a ) layout.
You can use three different layouts for different screen sizes ,and android will pick the suitable layout , but Using three different layouts for each type of screen format will not be a good idea , because it will cause problem in handling all layout , if screens are less then its fine but if number of screen increases it will get difficult . Like if you forget to add change in one of the screen size it shall crash with any exception .
What you can do is keep images of different size in different folders and practice layout to make standard in one layout by using layout weights , and margins in in dp .
See my this answer
Table Layout spacing issues
and check this layout will look similar for all screen sizes.
If your design is same for all screens sizes you can use dp and have only one xml for all screens.
But you should support icons for all screens.
I think it's less confusing David Ohanyan way, but forgot to say something...
Whenever you can, use styles in your xx_layout, images, etc, so you'll have 1 layout.xml and 3 styles files inside folders: values, values-small, layout-large.
At least for me, it's less confusing than opening 30 different layout files.

android - How to build complex views that stretch?

I'm at the planning stages of my first proper android app. Part of the brief is to have a very "good looking" interface (aka, plenty of graphics). As I'm a web developer, and I'm used to the CSS way of doing things, I'm struggling to understand how I will cater for all the different resolutions when building my layouts. To cut it short, my question is this: how do I build complex, image heavy views that can be seen in apps such as SoundHound (example view here, for those not familiar with this app: http://getandroidstuff.com/wp-content/uploads/2010/09/SoundHound-Android2.jpg)? Is there a way I can tile images in a similar way to the way I'd tile in CSS?
It is important that you know how all Layouts Views work before you start designing your main layout. Android OS by very design supports stretching of views and GroupViews. You need to use dp (density independent pixel) units.
In the example you provided, there are some nice nine patch PNGs. Check C:\android-sdk-windows\tools\draw9patch.bat if on PC. These pngs stretch properly as backgrounds for any resolution.
Linear layout have weight which allows you determine how much space will each child occupy, similar to the old column width for tables in %. Just like in old hml, to make a rich layout you use nested GroupViews (e.g. LinearLayout, RelativeLayout etc) and populate them with children views like ImageView, TextView and son on.
It is possible also to have text styled with <b>,<i> tags and have
<img src="DrawableName">
see an example: Html.ImageGetter
Opposite to a nested layout would be to use the RelativeLayout and determine the position of each child view by its top and left margin anywhere on the screen in relation to the top-left corner of their parent RelativeLayout.
Android has some conventions, that help you out when it comes to different screen sizes, screen densities, screen ratios ...
For example there is a directory called "drawable" where you can put the image resources for your application. However, if you want to ship your application for devices with different resolutions, you can create additional folders named "drawable-ldpi", "drawable-mdpi", "drawable-hdpi". The ldpi folder contains image resources for low density screens, mdpi is meant for medium density and hdpi meant for high density. The folder names are part of the Android conventions. When loading an image resource at runtime e.g. on a high density device, the system is looking for the image resource in the drawable-hdpi folder. It there is no image with that name, the system will look in the drawable folder.
This concept also applies to the xml layouts you define in your "layout" folder. Maybe you say that the layout homeScreen.xml needs to look different when the user switches from portrait to landscape mode. Then you can create a folder "layout-land". You create another homeScreen.xml in there and change its apperance to your needs. At runtime the system detects the current mode. If in landscape, it will first check if there ist a folder "layout-land" and if it contains the layout file with the correct name. If not, or when the user switches back in portrait mode and there is no folder "layout-port", the system looks for the layout file in the "layout" folder.
This is only a small part of it, but I hope, you got a first glance and everything was understandable. Further information can be found in the official refrence

Categories

Resources