Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Android数据绑定:在xml中设置默认可见性大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我在recyclerview中显示项目并使用数据绑定.在xml布局中我有这样的观点:

<include
        android:visibility="@{viewmodel.expandable ? View.VISIBLE : View.GONE}"
        bind:viewmodel="@{viewmodel}"
        layout="@layout/full_station_layout"/>

它运行良好,但我有一个问题:当recyclerview初始化并将项绑定到视图时,此布局在屏幕上闪烁一次,尽管初始值viewmodel.expandable为false.所以,我决定暂时隐藏这个布局并尝试在xml中使用default-parameter,如下所示:

<include
        android:visibility="@{viewmodel.expandable ? View.VISIBLE : View.GONE,default=View.GONE}"
        bind:viewmodel="@{viewmodel}"
        layout="@layout/full_station_layout"/>

但出了点问题:

error: 'View' is incompatible with attribute android:visibility (attr) enum [gone=2,invisible=1,visible=0].

所以,或者我@L_450_11@地使用了这个参数或Google从xml数据绑定规则中删除了这个关键字(我之前在Google开发人员身上看过xml中使用default-keyword的例子,但现在我不能)

解决方法

您可以在属性中设置已消失,可见,不可见.替换为下面.

<include
        android:visibility="@{viewmodel.expandable ? View.VISIBLE : View.GONE,default=gonE}"
        bind:viewmodel="@{viewmodel}"
        layout="@layout/full_station_layout"/>

大佬总结

以上是大佬教程为你收集整理的Android数据绑定:在xml中设置默认可见性全部内容,希望文章能够帮你解决Android数据绑定:在xml中设置默认可见性所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。