Can we use RelativeLayout or LinearLayout inside ConstraintLayout Android - android

I am developing an android app and I am used to relative/linear layout but now I decided to use ConstraintLayout. I am a novice in ConstraintLayout. I was reading some documents online and I have also read an official android document on ConstraintLayout.
ConstraintLayout give us a linear and flat view for our layout.
I have few doubts/questions in mind which I didn't found in the official document:
Can we use RelativeLayout or LinearLayout inside ConstraintLayout? Is it standard practice or not?
If yes, then does it create a multi-layer inside ConstraintLayout?
If no, then how should we manage some small UI components in ConstraintLayout? because I have one design which requires to combine two/three view and need some separate background. we can achieve easily this with RelativeLayout or LinearLayout?
Could anyone please help me to understand ConstraintLayout.

Can we use RelativeLayout or LinearLayout inside ConstraintLayout? Is
it standard practice or not?
No. You should not. You should read Optimizing Layout Hierarchies and Performance and view hierarchies
If yes, then does it create a multi-layer inside ConstraintLayout?
Same as above. [yes it creates multi layer]
If no, then how should we manage some small UI components in
ConstraintLayout? because I have one design which requires to combine
two/three view and need some separate background. we can achieve
easily this with RelativeLayout or LinearLayout?
There are ways to do almost everything using ConstraintLayout. As being a novice of this Layout, you may be frustrated when you face difficulty to create a few complex designs. But after some time you will forget to use even RelativeLayout :). Read the link provide by Rajnish in the comment and ConstraintLayout. There are several videos you may find to learn.

It is not considered best-practice to use RelativeLayout/LinearLayout inside ConstraintLayout but ConstraintLayout has many "Widgets" to help you design your screens
This is a great source to understand the different "Widgets"

Related

What is the benefit of having RelativeLayout after the introduction of ConstraintLayout?

I totally understand the advantage of having ConstraintLayout when flatenning nested UI's. But with the introduction of ConstraintLayout I see people adopting it instead of RelativeLayout even for simple layouts with a flat structure.
Does ConstraintLayout always performs better than RelativeLayout?
Specifically in the case when a view can be achieved with single flat
structure with no nested UI?
If yes, shouldn't Relative Layout be deprecated?
Any help would be much appreciated :)
I think that should be a matter of choice and customs. Some UI designers prefer RelativeLayout where others prefer ConstraintLayout. The ConstraintLayout can be used in many cases more than the RelativeLayout. And yes it performs better than the RelativeLayout but I think for just a single flat structure I can opt for RelativeLayout too though due to support tooling provided by the ConstraintLayout it makes it a better option if you need that feature.
That's my point of view.
Yes, it performs better, ConstraintLayout has designed with performance optimization in mind. Also, it's very straightforward to use by just drag and drop things.
I really like Constraint layout to develop complex layout faster than any other one, but in my opinion, it's harder to make changes on it when you need, but is just my point of view
Q1 - Does ConstraintLayout always performs better than RelativeLayout
A1 - I saw a lot of questions and answers on StackOverflow about that subject and here is what I can say base on those threads and my personal experience with ConstraintLayout :
In most cases, if you are using ConstraintLayout properly it will work faster but , there is no guaranty that this is what you will get all the time.
From my personal experience with ConstraintLayout, it is working really fast and in all of my layouts (both simple and complicated in terms of UI) it works faster than RelativeLayout.
Q2 - shouldn't Relative Layout be deprecated
A2 - Why I believe that Relative Layout should not be deprecated.
I honestly don't see any valid reason for RelativeLayout to be deprecated, altho I am using ConstaintLayout I first started with RelativeLayout and now I see it as another tool to build my UI.
If it's not broken don't fix it:
Don't forget that there are a lot of developers around the globe, some prefer
RelativeLayout and some prefer ConstraintLayout, let's keep it this way is what I believe - don't take the option to choose from the developers, give them the option to choose what to use.
ConstraintLayout is not a better solution for building UI as a fact, its just my opinion.
I really think that its something that depends on the developer and his decisions, therefore - no layout is better than the other and no layout should be deprecated (as long as it works)

Android XML Layout or Java Coded

I am starting to delve into Android Development and there is a lot of material online. The question is... What are the pro's and con's against the drag and drop XML design method vs coding the view manually? The only reason I ask on here is because online the views are mixed and they don't really back up what they're defending.
If I use the drag and drop method will I have issues further onto my development adventures? That is the thing that worries me the most... I don't want to learn the drag and drop method and then editting the XML to cater for my needs and then be handicapped by it.
For the beginner(s), I highly recommend not to use Drag and drop. We need to understand XML, to be comfortable with android widget. Understanding XML will come handy in future when creating custom styles and themes.
Here are few pointers before you dive in android XML layout
Try sticking with match_parent and wrap_content while defining android:layout_height or android:layout_width if possible
Make sure you have good understanding of RelativeLayout, LinearLayout and FrameLayout and how its child views are arranged.
Forget about ConstraintLayout, AppbarLayout and similar advance layout at current.
Try exploring TextView, EditText, Button, ImageView and ProressBar as far as possible.(This are most common widgets/views)
Try avoiding any tutorial related to ListView, its deprecated. Try using RecyclerView instead, it is one of the important widget that would be used in regular basis.

What is the best technique to develop Layouts in Android

I have been searching this on net and found various answers to this question.
I have been very confused to understand what is the best and standard way to create layouts in android.
Either,
Create a Parent Relative layout and put all items in the same
Layout.
Or
Create different relative or linear layout for each item, and a Parent layout that covers all the elements and child layouts.
Kindly guide me which one is the best and industry standard way.
Thanks
There isn't a standard way. All widgets are tools you can use for your convenience. However, be aware of performance when designing your layouts.
Maybe there is a golden rule:
The rule when constructing Android layouts is to make the layout shallow and wide rather than narrow and deep.
Please, read carefully this and this. Both tell us how to make fast Android layouts.

Use of <Space> in android layouts

What is the use of <Space /> in andorid ui, how is it any different from an empty linearlayout.
Is there any special use of <Space> in android ?
From the docs:
Space is a lightweight View subclass that may be used to create gaps between components in general purpose layouts.
Yes it is different than a LinearLayout in that it cannot do all (any) of the things that a LinearLayout can do. It's purpose is solely to add a gap between some things. By taking out all of the LinearLayout functionality it makes the view "lighter" which will mean less resource intensive.
Space is used to define empty spaces (or gaps) inside a layout.
It was introduced in API level 14 alongside GridLayout.
To get a feel of what it's all about, check out this tutorial.
It’s often possible to take a complicated layout and break it down into a set of nested linear layouts and, provided this nesting doesn’t get too deep, this is still a good choice for many simple layouts.
For use in hierarchies that are too deep and there are performance problems, is a lightweight View subclass. The keyword being 'lightweight'.

Which layout do you suggest

Here is a video of my app:
It's currently using absoluteLayout, and since absoluteLayout is deprecated i decided to change my layout.
So what Layout do u suggest using for this app?
Please see the part of the video, that the game has started, that's the only part with absolutelayout.
Thanks
It really depends if you want your UI to flow in a linear fashion or not. The majority of the time I use RelativeLayout with some instances of LinearLayout here and there. Relative seems to me the most flexible for me.
"You can achieve much the same layout by using a FrameLayout instead, and setting layout_margin attributes of the children. This approach is more flexible and will yield better results on different screens."

Categories

Resources