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.
Related
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.
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.
Hey Im new to android developing and I have a quick question. Is there a way to place buttons where I want them on the view? Right now they only seem to be placed where there is specific spots for them. Why cant i drag and place them where ever I want like in the iphone sdk for example?
Is there a way to do so or does this functionality not exist? thanks.
Android (eg. similar to Qt) uses a concept of layouts. This is especially useful when you're creating UIs that can be displayed on different devices with different DPIs, different screen resolutions, etc.
So instead placing your buttons at pixel coordinates you put them, independent of device screen resolution, into layouts.
Read more in User Interface documentation. Using Eclipse ADT plugin you can visually create layouts. You can even embed one layout into other, creating eg. LinearLayout in RelativeLayout. This gives much more possibilities of creating screen scalable applications (one app on phone and tablet for example).
There is AbsoluteLayout, but that class is deprecated. The recommended strategy is to use a RelativeLayout (you can control the position of views by setting layout margins) or build your own custom layout class.
An android UI screen is build for various screen sizes , due to which you can not specify an exact location for the UI component .
Android instead uses the concepts of Layouts where each layout has a different behavior. Here are a few of them.
LinearLayout aligns all children in a single direction — vertically or horizontally, depending on how you define the orientation attribute
TableLayout positions its children into rows and columns
RelativeLayout , one of the most used layouts , lets child views specify their position relative to the parent view or to each other (specified by ID).
Android uses layouts to design the UI. For example, a vertical linear layout stacks one element on top of the other.
AbsoluteLayout is the most precise, but it's also harder to maintain and can get messy.
I recommend RelativeLayout. It positions UI elements relative to other elements.
If you don't really need that much precision, one more option is nesting layouts within layouts. But doing that too much gets messy and RelativeLayout becomes the better option.
A UI element's position is determined by the layout you choose. See this link.
I'm trying to sort the layout for one of my Android apps, but I'm finding layouts a nightmare.
Principally I have to have a portrait and landscape layout for normal, small and large screens. So thats 6 layouts to maintain to start with, let alone having to launch the app on three emulators each time because my UI widets don't load in the built in previewer.
I might be showing my ignorance as a fairly new developer, but there must be a better way!
Are there any tools out there to help with Android layouts?
Thanks
You dont need to have that many layouts. Design only as many as you need, and never use absolute values, aditionally try to make everything look nice using fill_parent and wrap_content for you layout_width & layout_height tags. Android does most of the work it self.
This article contains a lot of usefull info:
Supportng multiple screens
You may find this applicaiton helpful for designing your layouts:
http://www.droiddraw.org/
Also, if you don't specify a layout for each rotation, android will use one - infact it can use one for everything. If you use fixed values it makes it much harder. Try using fill_parent and wrap_content, you android will take care of scaling the view for each screen type and rotation too.
As a tip, don't forget to include:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
above your relative or linear layout, and:
</ScrollView>
at the end - that way if the view doesn't fit on the screen (ie too much content) it will allow the user to scroll.
Eclipse's built in layout "editor" shows a reasonably good example of what a layout looks like. I would assume you're writing your application in Eclipse. If not, I highly recommend it. While not perfect, it's the best environment I've found.
you just need to master the proper use of RelativeLayout's and LinearLayout's. Almost all of my Layouts will start with a Relative and have Linear nested inside.
I generally don't use LinearLayouts without having either height or width set to 0 and using the weight attribute to make everything the same size.
i have used absolute layout in order to display image buttons in my application's main.xml.
how exactly it affects to using my app on different density screens..
Absolute Layout is deprecated and should not be used, it will make a mess of handling various screens.
Best practices for screen layouts
That is right, absolute layout will always make problem, that is why it is not at all recommended to use.
Please refer this Supporting Multiple Screens