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.
Related
I'm creating an application in Android Studio, but the application does not work on multiple screen sizes. I've seen on the internet, people using different xml files with the same name (just change the "setting" it, how large and etc). The best way to do the layout of my application is to use different xml for each screen size? Or does it have an easier way to create an xml and use this for the various screen sizes?
And to complete, I'm using the relative layout, but on the internet, people say that to use LinearLayout, which is better?
Thank you for your help and sorry for my english!
I'm creating an application in Visual Studio, but the application does not work on multiple screen sizes. I've seen on the internet, people using different xml files with the same name (just change the "setting" it, how large and etc). The best way to do the layout of my application is to use different xml for each screen size? Or does it have an easier way to create an xml and use this for the various screen sizes?
Yes. If you want to support a different layout for a larger / smaller screen size, you have to provide a diffrent xml file. You can do this by creating a layout folder. https://developer.android.com/training/multiscreen/screensizes
On the other hand, if you think your project can reuse other layouts of your app and jam them together if the screen is larger, you probably use fragments for these kinds of situations.
And to complete, I'm using the relative layout, but on the internet, people say that to use linear layout, which is better?
The type of layout you use depends on your use-case. LinearLayout for example is very useful for a simple layout with components arrange vertically or horizontally. If your layout is more complex, a RelativeLayout would be better to use BUT...
I would recommend you to use ConstraintLayout instead of a RelativeLayout. The two layouts position items relative to other components but ConstraintsLayout is way more powerful that RelativeLayout. You should take a look at it.
I read something about supporting multiple screen sizes in Android.
For that most of the answers recommended to create different layouts
(layout-normal, layout-small, and so on). But that would mean that
I have to define all my layouts multiple times. I don't think that
this is a smart solution.
Is there no way to create just one layout and to automatically scale
it for any display size?
There are several parameters in layouts in android that adapt themselves to the size of the screen (fill_parent, center...), however I have not seen in android's layout parameters for everything... for example 1/3 of width.
Finally what I am doing is the following:
One layout per architecture of the interface. For example, in tablets I change the architecture, integrating sometimes 2 layouts in one.
Include, programmatically, changes of sizes. For example, an button I want to be 1/3 of the screen I need to programmatically obtain the width of the screen and change the button size.
Always include several sizes of icons that android automatically selects depending on resolution.
But there is a significant part of the job that needs to be done "by hand".
I am trying to create a calculator app and I've been having problems with the xml layout.
Due to the amount of button even though I use dp's to determine the size of each button from screen to screen the result varies...
Am i supposed to create the layout in java so I can get the screen dimensions?? if so can I have an example?
You can design the layout file and then make a few versions of it with different sized buttons. put them in res/layout-small/, res/layout-large/, and res/layout-normal/. The system will pull the proper xml file according to what size display the device has.
Another option is to try to design the layout with specifying a size in dp, instead use android:layout_weight and android:weightSum to achieve the proportions you are wanting. Then it should scale itself based on the device without needing any different xml files.
I am developing an application for whole android devices. But resolation of screens are different and that is the biggest problem how it looks. So, I want to make resizing controls and also I used absolutelayout but It is still same.. I give value to controls as dp ..
How can I solve this problem ?
You don't resize the screen of an android device - you make your app instead work with the various screen sizes.
The relevant docs are here.
You cannot hardcode the dimensions of your layout and expect it to work on every screen size. And there is no method which automatically does it unless you write it.
You might want to change your approach, use Relative Layout or Linear Layout instead and use values like fill_parent and wrap_content while designing your layout.
Another approach Android developers follow is use different resource files for different screen sizes and Android loads them automatically at runtime.
Refer to this for more info on how to work with different screen sizes effectively.
I am creating a simple game in android so I can create something and learn how to program in Android (I'm a noob).
Right now in my layout editor (i think thats what its called, basically the place where you can create your layout xml files) there are many sizes on the top left... which one should i target? do i need to make a separate layout for each one of them?
Thanks!
R
The screen size selection is only intended to give you an impression of what the layout looks like on various screen sizes and densities. A good place to get started is Common Layout Objects and Supporting Multiple Screens.
When developing for Android, you should not target a specific screen size, but instead make layout elements fit proportionally. An exception may be x-large displays such as tablets, for which a great read is Distributing to Specific Screens. An example of getting elements to position nicely is this question.