Search code examples
androidandroid-motionlayout

What is the different between android:visibility and PropertySet android:visibility in Constraint


I just started working with MotionLayout. After testing, I see that I can use both android:visibility="gone" or PropertySet android:visibility="gone" to hide a view.

<Constraint android:id="@+id/text_video_title"
    android:visibility="gone"
    >
    <PropertySet android:visibility="gone" />
</Constraint>

I check the MotionLayout document but it doesn't mention. Is there any different between theme? May be it have some benefit of using PropertySet android:visibility


Solution

  • Good question. By default Constraints present in the layout file are used as the default in a ConstraintSet.

    The layout file for a ConstraintLayout or MotionLayout can contain 3 types of attributes.

    1. Constraints that affect layout
    2. View Transforms that apply post layout such as scaleX, rotate
    3. Subclass specific attributes such as text

    ConstraintSets

    If you have more than the android:id attribute in the <Constraint> tag. it erases all underlying constraints (type 1 and 2). Which means you will need to define all constraints needed to layout that view (things like layout_constraintTop_toTopOf=.. )

    If you only have id and you have sub sections such as <PropertySet> <Transform> <layout> It will erase only those sections you define.

    2.1 adds <ConstraintOverride> which will override only the tags you put but you cannot override layout_constraintXXX tags.