使用
AS 3.2.1
具有
targetSdkVersion 28
1.我有
RecyclerView
包含按钮和进度条的项目。进度条的可见性绑定到
ObservableBoolean
初始值设置为
错误的
.
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true">
<androidx.appcompat.widget.AppCompatImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:onClick="@{() -> data.onLoad()}" />
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="@{data.isLoading ? View.VISIBLE : View.INVISIBLE}" />
</RelativeLayout>
在按钮的
onClick
我试图通过将这个值设置为
符合事实的
:
public void onLoad() {
isLoading.set(true);
}
什么都没发生。进度条不可见!然而,如果我设定
最初的
重视
符合事实的
进度条将可见!
问:
如何使用数据绑定最初隐藏视图,然后显示它?(请注意,我所有的绑定都可以工作,除了这个可见性切换。)
使现代化
事实证明,由于数据绑定框架中存在一些奇怪的优先规则(bug),以下方法破坏了双向绑定:
public boolean getIsLoading() { return isLoading.get(); }