gpt4 book ai didi

安卓数据绑定(bind) : set default visibility in xml

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:22:33 27 4
gpt4 key购买 nike

我在 recyclerview 中显示项目并使用数据绑定(bind)。在 xml 布局中,我有这样的 View :

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

它运行良好,但我有一个问题:虽然初始值 viewmodel.expandable 为 false,但在 recyclerview 初始化并将项目绑定(bind)到 View 时,此布局在屏幕上闪烁一次。因此,我决定暂时隐藏此布局并尝试在 xml 中使用 default 参数,如下所示:

        <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].

所以,或者我错误地使用了这个参数,或者谷歌从 xml 数据绑定(bind)规则中删除了这个关键字(我之前在谷歌开发人员的 xml 中看到过 default-keyword 的用法示例,但现在我不能' t)

最佳答案

您可以在default 属性中设置gonevisibleinvisible。替换为以下内容。

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

关于安卓数据绑定(bind) : set default visibility in xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50296658/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com