I have a list of items and I'm using RecyclerView to showing it.
This is an example of my list:
I need to understand what is better to use for item layout: RelativeLayout or ConstraintLayout in my case.
On the one hand, the RelativeLayout is considered as deprecated and recommended to use ConstraintLayout. But at the same time, it is better to use the ConstraintLayout when there are many child views, and then we will get a performance improvement. But I only have two child views and I have a feeling that the ConstraintLayout can only hurt.
Please tell me which view group is better to choose in my case?
Use Constraint Layout Only. Because Relative Layout is deprecated and now days most of the people not using.The Relative layout also fluctuates depending on screen.The
Constraint layout remains fix in all screen resolution.
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.
Can one relative layout / linear layout can have multiple constraint layouts? Do they affect on the performance of application while inflating?
Also, can one constraint Layout can have multiple constraint layouts?
If you are talking about nesting view groups(relative layout/linear layout/constraint layout) inside another view group, yes it is possible. But the issue with nesting view groups is each of the view group has to perform calculations to constrain its children. This is usually done in a depth-first search manner. So it will affect the inflation speed and thus the overall performance of the layout.
It is always better to keep the hierarchy as flat as possible. Which means maximum avoid the nesting of view groups wherever possible.
Nested view hierarchies should be avoided because it takes more time in rendering. To overcome from box-model logic (in HTML), ConstraintLayout has been introduced. It is clearly mentioned in the documentation.
I searched for a few hours over the internet but I didn't find any example or documentation explaining how to create an horizontal list view with fixed number of elements.
Basically, I would like to have, let's say 3 elements out of n(total number of elements) which are displayed on the screen without taking into consideration the size of the scree. The elements can be bigger or smaller proportionate to the screen but the number of visible elements should be the same, fixed. see the image.
How can I do that? Any hint is appreciated! Thank you!
You can use TwoWayWiew third party library (i dont really recommend this solution), or if you want to avoid to use lib for this, just use RecyclerView, and you can set HORIZONTAL param to layout manager.
I would not use a ListView for this, but a RecyclerView instead. Performance is better in a RecyclerView and I honestly find them easier to work with. You can allow for horizonatal scrolling via the LayoutManager for your RecyclerView.
If don't mind scrolling horizontally by 3 items you could use a ViewPager with each View containing a LinearLayout (orientation horizontal) with three of your elements that have a
android:layout_width="0dp" and an
andriod:layout_weight="1"
for even distribution.
When you "scroll" you would just animate the next "page" into the screen bringing in the next 3 elements.
This might not be the most elegant solution but I think it would behave the way you want.
use the linear layout with its orientation set as horizontal under the relative layout
I need to implement an overlay (translucent) screen for my app, something similar to Showcase View
My guess was to use FrameLayout for this usecase, because it is used to stack items on top of each other. But I was surprised to see that the above library uses RelativeLayout.
My question is when to use FrameLayout then, if not in cases like this? What are the disadvantages if I go the FrameLayout way?
A common rule of thumb when choosing layouts is to select the combination that results in the smallest number of nested layout views.
Specific to your question, RelativeLayout is larger and more capable than the much simpler FrameLayout. So for simple layouts, the latter is probably more efficient. But if using RelativeLayout and it's added positioning options allows you to implement your GUI in a smaller number of layout views, then that would likely be a better choice.
Here's a page that discusses some trade-offs and demonstrates some helpful tools to use when designing your layouts. It mostly talks about RelativeLayout and LinearLayout, but is also apropos to your choice between RelativeLayout and Framelayout. Just keep in mind that FrameLayout is an even simpler layout.
Edit (2017): For even more complicated layouts, you may be able to avoid nested layouts by using ConstraintLayout.
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.