1

I'm using ConstraintLayout in most of my layouts, and I want to know what's the best practice in the performance aspect:

  1. Using a guideline as a view's limit, including as a margin limit.

Example: 4 guidelines in total, no margins.

guideline picture

  1. Using a view margin, which will result in less accurate spacing, because I will need to insert an arbitrary number of dps.

example: 2 guidelines in total, 2 margins (top + bottom)

android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"

margins picture

If you have another option, I will be happy to read it. Also, I would like to know how to track performance of layout configuration such as this (where have you looked / what have you used to give me the answer).

Thanks.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Or So
  • 53
  • 1
  • 10

1 Answers1

2

In this case, you can get the same result without guidelines. Percent dimensions can be used in ConstraintLayout.

Just set the "layout_constraintHeight_default" attribute to "percent" (to use percentage units), and set the percentage using "layout_constraintHeight_percent". (width related attributes are available too)

As for the layout performance between 4 widgets, and, 2 widgets and 2 constraints(margins). I am sure that the latter will do better as it takes a smaller layout to render. However, in this case, the difference is insignificant.

Rami Jemli
  • 2,550
  • 18
  • 31
  • You are right "difference is insignificant" so I have chosen to use a keyboard layout as part of figuring out the best performance practices for constraintLayouts see-> https://stackoverflow.com/q/52847213/1815624 – CrandellWS Oct 17 '18 at 04:18