Eliminate Space view using Constraint Layout
If you have read my previous blog on Challenge of Arranging Horizontal TextViews, this would interest you further.
Just to recap, we use Space
to help partition out the TextViews properly as below, so we have equal spacing between the text.
This allows proper animation as below
A Newer and Better Way
Upon reading my blog, Jorge Aguilar has responded and demonstrate that this could be done using ConstraintLayout
, and the good news is, Space
is not needed, yet achieve the same result.
A little intro to Constraint Layout
ConstraintLayout
is the newest introduced layout that enable user to define Constraints on the views with other views or it’s parent.
The constraint that we will use here is defined as layout_constraint<AnchorX>_to<AnchorY>Of
, where Anchor
could be either Top
, Bottom
, Start
and End
.
Given two layouts, if we want them to be horizontally aligned together, with equal space in between, we’ll chain them through the constraints defined below.
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/first"…