A Battle towards Performance -ConstraintLayout vs Other Layouts Part -3
Now we already know various tools that can be used for measuring the performance of layouts with different ViewGroups we have in Android.
Here, I am sharing the result for different layouts testing performed on Coolpad and Android 6.0 Marshmallow.
Note: This may vary with the device as well as API level. Also, there are many updates to the layouts as well. Please perform the result on your end too.
I also created a Github project for your reference. You can check out the code for various layouts there.
Here are the results -
- View inside another View in the centre-
2. RecyclerView with 100 Items
3. Simple UI with TextViews and Images
4. Complex UI with Images, Text, ScrollView, Buttons etc.
Please Note:- Always measure your layout performance through systrace and GPU overdraw before finalizing any layout. These results can vary from device to device and with respect to the OS version too. On average, however, the results will remain the same.
Conclusion -
The complete analysis of the various layouts tells us -
- With Complex UI where we can have more hierarchies, it is wise to use constraint layouts.
- If you are using LinearLayout with weights/RelativeLayout with hierarchies, replace them with Constraint layout.
- For simple layouts with just one view centred on the screen, go for Frame layouts.
- For simple screens, where you have to place views just horizontally and vertically, go for LinearLayout.
References -
- https://medium.com/comparethemarket/three-key-lessons-when-migrating-to-constraintlayout-dff38c31a47
- https://github.com/googlesamples/android-constraint-layout-performance
- https://stuff.mit.edu/afs/sipb/project/android/docs/tools/debugging/systrace.html
- https://medium.com/rosberryapps/make-your-custom-view-60fps-in-android-4587bbffa557
- https://medium.com/mindorks/android-app-performance-optimization-cdccb422e38e
Originally published here.
Please feel free to share your opinion in the comments.