I have two groups defined inside a ConstraintLayout in my layout. I want them to have visibility opposite to each other. So if group1 is visible then group2 should be gone and vice versa. I am trying to use data binding to achieve this.
<data>
<import type="android.view.View" />
</data>
<android.support.constraint.Group
android:id="@+id/group1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"
app:constraint_referenced_ids="..." />
<android.support.constraint.Group
android:id="@+id/group2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="@{group1.visibility == View.VISIBLE? View.GONE : View.VISIBLE}"
app:constraint_referenced_ids="..." />
But I am getting a compilation error that says:
****/ data binding error ****msg:Could not resolve the two-way binding attribute 'visibility' on type 'android.support.constraint.Group'
What am I doing wrong?
I don't know why that error is happening, but this worked for me:
group1.getVisibility() == View.VISIBLE
With that said, I couldn't get the constraint.Group
to work as advertised. Also, to make them opposite each other, presumably you would need similar logic in group1
's visibility, but that would be circular. Why not bind these to a ViewModel that controls when each should be visible?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With