-
Notifications
You must be signed in to change notification settings - Fork 174
MotionLayout constraintSet types
John Hoford edited this page Dec 16, 2022
·
1 revision
New for 2.2.0 ConstraintSet's now have a concept called constraintSetTypes Types are a series of string that can be used to identify / lookup a constraintSet.
Added are two methods:
class MotionLayout {...
public int[] getMatchingConstraintSetIds(String ... types){...}
}
class ConstraintSet {...
String[] getConstraintSetTypes();
In xml constraintSet's now have one more attribute:
<ConstraintSet android:id="@+id/foo" constraintSetTypes="a,b,c" > ..
so now you can query a motionLayout for constraintSets that match a series of strings
MotionLayout m = findMotionLayout()
String[]types = m.getConstraintSet(m.getCurrentState()).getConstraintSetTypes();
int[]matched = m.getMatchingConstraintSetIds("a","b")
m.transitionTo(matched[0])
Typically you would use this when you have a Matrix of States For example
- Open, Closed
- list, detail
- friend, unknown
This would result in 8 permutations you would then need id r.id.open_list_friend, r.id.open_list_unknown
This allows you to tag a Constraintset with
constraintSetTypes="open,list,friend"
This allows you then to know an query this list.