gpt4 book ai didi

android:在显示之前具有条件延迟的可见性

转载 作者:太空宇宙 更新时间:2023-11-03 11:04:13 25 4
gpt4 key购买 nike

我正在尝试使用 android 数据绑定(bind)。但是当我在条件下使用 android:visibility 时遇到了一些问题。比如 android:visibility="size == 0 ? View.GONE : View.VISIBLE”。

当它返回 false 时,它​​会先显示这个 View ,然后一会儿它就消失了。

我可以解决这个问题吗?或者这是数据的错误?

最佳答案

我曾经尝试过这样的代码android:visibility="@{size==0?View.GONE:View.VISIBLE}",但是编译不了,不知道为什么,可能是bug。

所以我使用以下代码代替,首先,编写一个 Helper。

public class Helper {
@BindAdapter("bind:attr")
public static void setAttr(View view, Object obj) {
if (someCondition(obj)){
view.doSomething();
}
}
}

其次,在xml文件中使用自定义属性

<View
...other attrs...
app:attr="@{obj}" />

note:

the 'attr' in the annotation must be the same with 'attr' used in xml file.

the View in the static method must be the same with the View in xml file.

我的Gradle版本和dataBinder版本

dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath "com.android.databinding:dataBinder:1.+"
}

并且,删除与此 View 无关的其他操作。

或提供您的 Activity 代码。

关于android:在显示之前具有条件延迟的可见性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35787096/

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