I was trying to create different layouts for different screen sizes with swXXXdp layout files. Unfortunately I still can't separate 5,0" from 6,3" as visible on attached image.
Both sizes still use the same file: layout-sw412dp. Any idea for this?
I suggest you yo use Constraint Layout, maybe it could be useful for your goal...
ConstraintLayout allows you to create large and complex layouts with a flat view hierarchy (no nested view groups). It's similar to RelativeLayout in that all views are laid out according to relationships between sibling views and the parent layout, but it's more flexible than RelativeLayout and easier to use with Android Studio's Layout Editor.
doc
Related
just a simple question, should we always use Constraint Layout for everything? why another layout still used today?
I want to make a simple login layout like this, should I use Linear Layout or Constraint Layout?
usually, I make every layout with Constraint Layout but my friend told me to use Linear Layout for the login, is it wrong if I use Constraint Layout? thanks before!
ConstraintLayout helps you to avoid using nested layouts and it causes better performance. it's not wrong to use it for everything but if you know that you are not going to have nested layouts, for example, three Textviews respectively, you can use LinearLayout. ConstraintLayout needs more XML code than LinearLayout for simple structures, and using LinearLayout is better for these situations.
I would say ConstraintLayout is more versatile and has better performance compared to RelativeLayout, But LinearLayout has its own significance in android you can specify weights of view using LinearLayout and for complex UIs I would say going with ConstarintLayout is a better option because of its performance and in ConstarintLayout you can specify the view positions, heights, widths, margins and paddings based on screen sizes rather than hard coding the values to fixed dp
https://android.jlelse.eu/constraint-layout-performance-870e5f238100
The above link gives more overview of LinearLayout vs ConsrainLayout performances.
No it it's depends on your need, if you want to make complex layout and want to make them responsive then you can.
I have been mostly designing my views using Relative layout as it works great when you put things positioned from the right edge, center or simply relative to each other. That would great on different screen sizes so the views are more spread.
With the introduction of constraint layout, I find it that it is more powerfull and it achives the same purposes while giving more flexibility.
Does that mean that Relative layout is no longer needed and can be replaced with Constraint all the time? Is there a situation where you shouldn't go constraint view and go for relative layout instead?
Thank you
It is not much different than other layouts you are probably already using (like RelativeLayout or LinearLayout). The attributes are very similar to the ones used with Relative Layout.
This is primarily designed as a visually oriented tool. The visual editor is intended to be the main way developers interact with their layouts.
The main goal of this new layout, is to help developers create complex layouts that are optimized to rendez quickly. In fact, its aim is to reduce layout hierarchies induced by other layout types.
Hello! I have just started playing with android layouts and i wonder if there is a general way of applying basic layout so that it will adjust itself to multiple screens and automatically to landscape view. For example:
In the picture above, I have added some buttons. Now what i want to learn is which layout or options(like weight,gravity,alignment) to b used so that they remain the same in Every view & on every screen. Some says to use linear layout within linear and then add weight and alignment. They said that by doing this, you have flexibility to remove any button and yet no other button looses its place(unlike in relative layout). Can there be better way that will have same layout on all screens and yet flexible??
You can use multiple linear layouts if you want to create a FORM.
otherwise Absolute layout is also good but not much preferable.
Relative layout needs practice, as you have to set widgets with respect to other.
multiple linear layouts may be useful.
RelativeLayout is very easy to use and if you learn to align the widgets in it, the layout will look the same on every screen BUT it's good for a layout that is very simple (few widgets on layout) or a layout that you know that will never change because changing on RelativeLayout is so hard and the best way is editing the XML not working on DesignView.
LinearLayout is not flexible like RelativeLayout but making change in it is so simple and other widgets will not lose their positions.
After all if you want to design layout for multiple screen size I recommend to use Fragments.
I have read many articles regarding layout, but I am still quitely confused. My questions are:
When to use relative layout? Example?
When to use table layout and why we can't use it instead of relative layout?
When to use linear layout?
I just need brief answers.
When use which layout?
I think It depends on your UI, and most important thing that how you create optimized layout.
From definition : -
LinearLayout – designed to display child View controls in a single row or column. This is a very handy layout method for creating forms.
RelativeLayout – designed to display child View controls in relation to each other. For instance, you can set a control to be positioned “above” or “below” or “to the left of” or “to the right of” another control, referred to by its unique identifier. You can also align child View controls relative to the parent edges.
TableLayout – designed to organize child View controls into rows and columns. Individual View controls are added within each row of the table using a TableRow layout View (which is basically a horizontally oriented LinearLayout) for each row of the table.
References :
Creating Efficient Layouts
Common Layout Objects
And most important Hierarchy Viewer
at first there is some confusion about these layouts but as you start playing with these three layouts u will get idea where to use what.. I worked on relative-layout the most.
Consider i want to use a widget always at bottom of screen then with table or linear layout this is not possible always.. without feeling screen other two can not make item at bottom but relative can do.use of any type of layout depends on your screen requirements.
I started out using relativelayout. But recently I've switched to using mostly linearlayout.
The reason is kind of hard to explain, but take this as an example: Say I want a layout that has two images centered in the middle of the screen. Both images should take up 1/4 of the screen width and 1/4 of the screen height. This is impossible to do with relativelayout assuming you want it to work exactly the same on all devices. But you can do this with Linearlayout. By creating vertical and horizontal parents, you can create "boxes". To accomplish this you must learn about weigthsum and weigth. Parent layouts should have the weigthsum attribute and children should have the weight attribute.
Anyway, my point: Relativelayout is easy to use but it's also deceptive. You may think that your layout will look exactly alike on all device, but most likely, they won't look alike. The reason for this is:
With relativelayout you must define size with either dp or px(assuming you don't fill parent or wrap content).
Different devices have different aspect ratios.
I hoped that helped in terms of understanding relative and linearlayout.
I am new to android.
As far as I know, there are different layouts like the liner layout, the table layout, and some others. I would like to know in which case what layout would be suitable.
I am unable to categorize the exact differences between the layouts.
Also, can someone please tell me what the specific meanings of the attributes like fill_parent, wrap_parent are?
What type of layout to use really depends on how the layout you are trying to build looks. If you have a simple layout of items one after another, a LinearLayout usually is the best choice. It's easy to work with, but the drawback is that you can't really customize the layout very much. All your views will just end up in a horizontal or vertical list. A RelativeLayout gives you a better way of adding Views that are right/left/top/bottom aligned compared to its parent view. And last but not least, the TableLayout is really great if you are building a grid of views.
All layouts have specific uses. Read android.developers.com, fill parent means your view will cover whole screen area, wrap-content covers that much area that is occupied by the layout's child views. Match - parent takes area equal to its parent area.But using match parent is not good.