I show items in recyclerview and use databinding. In xml layout I has such view:
<include
android:visibility="@{viewmodel.expandable ? View.VISIBLE : View.GONE}"
bind:viewmodel="@{viewmodel}"
layout="@layout/full_station_layout"/>
It works well but I has one issue: while recyclerview initializing and bind items to views this layout flashes once on the screen although initial value viewmodel.expandable is false. So, I decided temporary hide this layout and tried using default-parameter in xml like this:
<include
android:visibility="@{viewmodel.expandable ? View.VISIBLE : View.GONE, default=View.GONE}"
bind:viewmodel="@{viewmodel}"
layout="@layout/full_station_layout"/>
But something went wrong:
error: 'View' is incompatible with attribute android:visibility (attr) enum [gone=2, invisible=1, visible=0].
So, or I incorrectly use this parameter or Google remove this keyword from xml databinding rules (I've seen example of usage default-keyword in xml on Google developers before, but now I couldn't)
You can set gone
, visible
, invisible
in default
property. Replace with below.
<include
android:visibility="@{viewmodel.expandable ? View.VISIBLE : View.GONE, default=gone}"
bind:viewmodel="@{viewmodel}"
layout="@layout/full_station_layout"/>
Check if you have already imported the View class.
<data>
<import type="android.view.View"/>
<variable ..... />
</data>
Also, the default correct syntax for default value for visibility is default=gone
, no default=View.GONE
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