Mastering ConstraintLayout in Android
Why Stack Overflow recommends it
Stack Overflow users link it when explaining why a flat ConstraintLayout hierarchy matters for performance and when pointing to ConstraintLayout usage.
Recommended by 2 people across 2 different months, 2017 to 2019.
What it is
A 47-minute talk from GDG Johannesburg in which Rebecca surveys Android layout types and then focuses on ConstraintLayout. She demonstrates barriers, chains, guidelines and constraints in a practical walkthrough and covers tools for checking layout performance.
What people said
Recommends j2emanue · 2017-09 · Stack Overflow · on “360dp in MDPI not matching in xxhdpi”
i finally figured this out. this is one reason constraintLayout was built to rectify these issues. in this particuular case it was about aspect ratio in a view i was using. so to make it take up the entire space of the activity left and right i did the following and the aspect ratio is maintained. keep i mind i wanted a 360 x 500 ratio: <com.mobile.myapp.customViews.SwippableViewPager android:id="@+id/pager" android:layout_width="0dp" android:layout_height="0dp" android:layout_marginLeft="0dp" android:layout_marginRight="0dp" android:layout_marginTop="0dp" app:layout_constraintDimensionRatio="H,360:500" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintLeft_toLeftOf="parent" ap
Recommends bergestahl · 2019-05 · Stack Overflow · on “Navigation component with viewpager performance issues”
Consider using FragmentPagerAdapter instead of FragmentStatePagerAdapter From the documentation: FragmentPagerAdapter - Use this when navigating between a fixed, small number of sibling screens. FragmentStatePagerAdapter - Use this when paging across an unknown number of pages. FragmentStatePagerAdapter optimizes memory usage by destroying fragments as the user navigates away . Also try to use ConstraintLayout where you can to keep your view hierarchy flat. In this video the speaker explains why that is important: [this video]
Cites Pavel Poley · 2018-04 · Stack Overflow · on “Aligning controls to appear horizontally centered on screen”
Check this code, but you should work with ConstraintLayout directly, without nested layouts. Also you should use dp instead px . <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android=" [LINK] " xmlns:app=" [LINK] " xmlns:tools=" [LINK] " android:layout_width="match_parent" android:layout_height="match_parent" tools:background="?android:attr/colorForeground" tools:context=".MainActivity"> <LinearLayout android:id="@+id/linearLayout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toT