Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between ConstraintLayout and RelativeLayout

I am confused about the difference between ConstraintLayout and RelativeLayout. Could someone please tell me the exact differences between them?

like image 742
b2mob Avatar asked Sep 25 '22 19:09

b2mob


People also ask

What is the difference between RelativeLayout and ConstraintLayout?

Unlike RelativeLayout , ConstraintLayout offers a bias value that is used to position a view in terms of 0% and 100% horizontal and vertical offset relative to the handles (marked with a red circle). These percentages (and fractions) offer seamless positioning of the view across different screen densities and sizes.

Which is better ConstraintLayout and RelativeLayout?

ConstraintLayout has flat view hierarchy unlike other layouts, so does a better performance than relative layout. Yes, this is the biggest advantage of Constraint Layout, the only single layout can handle your UI.

What's the difference between LinearLayout and RelativeLayout?

Android Layout Types Android provides the following ViewGroups or layouts: LinearLayout : is a ViewGroup that aligns all children in a single direction, vertically or horizontally. RelativeLayout : is a ViewGroup that displays child views in relative positions.

What are the differences between RelativeLayout and FrameLayout?

RelativeLayout based on relation of views. It is a layout manager that helps you arrange your UI elements based on some rule. You can specify things like: align this to parents left edge, place this to the left/right of this elements etc. FrameLayout allows placements along Z-axis.


1 Answers

The intention of ConstraintLayout is to optimize and flatten the view hierarchy of your layouts by applying some rules to each view to avoid nesting.

The Rules are similar to RelativeLayout, for example setting the bottom edge to the bottom of some other view.

app:layout_constraintBottom_toBottomOf="@+id/view1"

Unlike RelativeLayout, ConstraintLayout offers a bias value that is used to position a view in terms of 0% and 100% horizontal and vertical offset relative to the handles (marked with a red circle). These percentages (and fractions) offer seamless positioning of the view across different screen densities and sizes.

app:layout_constraintHorizontal_bias="0.33" <!-- from 0.0 to 1.0 -->
app:layout_constraintVertical_bias="0.53" <!-- from 0.0 to 1.0 -->

The Baseline handle (a long pipe with rounded corners, below the circle handle) is used to align the content of the view with another view reference.

Square handles (on each corner of the view) are used to resize the view in dps.

enter image description here

This is totally opinion based and my impression of ConstraintLayout

like image 177
Nikola Despotoski Avatar answered Oct 16 '22 13:10

Nikola Despotoski