Single layout for multiple screen without different layout folders in android - android

I have a doubt. If i have one single xml file let's say res folder--> layout folder--> my.xml. i want to display this my.xml to all multiple screen size without creating layout-mdpi, layout-hdpi etc.., May i know what is the simple and best way to achieve this concept ??
Thanks in advance

Place the file at res\layout\my.xml
Every single device will get that layout by default unless you create an alternative.

If you have a single layout file in the default location (res/layout/my.xml), then it will be used on all the devices that your app can be installed on.
However, that's usually not what you want because it will look very different on a device with a different size than what you developed on. To handle this, you can start by creating another layout file in another directory (res/layout-sw600dp/my.xml). This layout would be used for devices where the smallest width (sw) is 600dp, ie, tablets.

Related

android app development compatible to multiple screen sizes

consider a requirement of an app which need to be run on different screen sizes. lets say app has text fields ediboxes list view etc... and in each screen size the width/height of each ui component has to vary. how to desing an UI for this kind of requirement. please suggest.
Use Width and Height as fill_Parent or wrap_content..
if you are using images make different sizes images and put it in drawable-hdpi,drawable-ldpi,xhdpi,xxhdpi.The Sizes for those imagaes are in developer.android.com
In the res folder,there exists folder named layout,that the default folder which the system find the layout defination.But people also can make other folder like
layout-480x800
layout-1024x768
and so on ,and put the layout files in it.
When the app run on a device which have the certain size,the app will auto find the layout defination in the same folder,if cant it will use the default defination.

Android layout for different screen sizes

I am new to android and i am trying to create a single layout for different screen size.Is it possible or am i want to create different layout for different screens
Of course you can only provide the layout in res/layout, but it might look ugly on other screen sizes, even though (or because) Android tries to scale it.
It is not possible to define layouts for different reolutions in a single file. It's just possible to design the layout to be dynamic so Android can adjust it to the given resolution as good as possible.

how to design one xml layout for all devices without creating folders or different sized images.

I want to design app in which i am using one xml layout,I want to use that layout for every device but i dont want to create new folders for small,large or extra large images in drawable.
how we can design one layout which is fit to all devices without creating images for ldpi,mdpi,hdpi?
Thanks in advance!
just put that layout in the 'layout' folder and your image in 'drawable' folder, one place no more :)
Android system will auto scale resource for you. But the UI will look bad.

Select layout xml files most appropriate, depending on screen size

I would like to know if You Could select a layaout xml Differently Depending on the size of the phone screen.
I try to be more clear, I make more layout xml file, and I would like my app handles this statement
setContentView (R.layout.main)
first verifying on that size of the display is performed, and Therefore You Set the most appropriate layout xml
What you could actually do is the following:
Create a new folder for each desired configuration and name that folder with qualifiers.
If you want your application to have a different main.xml layout for different screen sizes you should make the following folders in your project.
/res/layout-small
/res/layout-normal
/res/layout-large
/res/layout-xlarge
In each of those folders have your different main.xml file layout (or whatever resource you want). Android will pick the one it matches with the device is running your application.
You can even add different resources for different configurations for drawables and even for language.
More info: http://developer.android.com/guide/topics/resources/providing-resources.html
Have you looked at this page yet?
You can query the size of the device screen, and then select which xml layout you want to use for that size screen...

Android - How to create layout as generic as possible?

I am having trouble in creating generic layouts for my application. As expected, it can be used in a variety of devices and I want it to work properly for each of them. There are several approaches to achieve this problem but I want to create an xml file (similar like web.config files) and at the very beginning of my application I want to take the device's screen width and height and calculate each control's (textview, spinner, button etc.) attributes (such as margin, padding,width, height...) according to this width and height and save these calculated values into my xml file. Finally I want to reach these values from my layout xmls so my layout's visual will be independent from the device and will work properly for each device. Can this be achieved? I could not find any similar solution on the internet. Can anyone help me?
Thanks in advance.
You can do most of this without hard coding values using RelativeLayout and similar mechanisms. The two pass dynamic layout system is made for exactly what you're describing.
However, when you need to be more specific, that's where the dynamic resource system can help you out. For everything you define in res/drawable, res/layout, res/values, etc, you can define specific implementations for device orientation, pixel densities, screen size or even language by qualifying sibling directories with the correct format. Provide a resource with the same name in different folders, and the system will decide which to use based on the runtime environment.
Give this a look:
http://developer.android.com/guide/topics/resources/providing-resources.html
I would not use custom measurements to dynamically set layout parameters. Android specifically has a variety of functionality to address this for you (including supplying multiple image resources, or layouts specific to a screen size).
I have discovered that the more you try to customize the Android layout with hard-coded values (always use DP if you do want to set specific parameters).
Bottom line, you should not try to re-invent the wheel, and just use the well-designed functionality that Android has already built-in to accomplish what you want.

Categories

Resources