我的布局文件中有两个父母,比如说一个粗略的骨架
<ConstraintLayout>
<ConstraintLayout
id = id1
visibility = viewModel.visibility1>
.....
</ConstraintLayout>
<ConstraintLayout
id = id2
visibility = viewModel.visibility2>
....
</ConstraintLayout>
</ConstraintLayout>
我的视图模型就是这样
ViewModel.java
private boolean isActive;
public void setActive(boolean isActive){
this.isActive = isActive;
notifyPropertyChanged(BR.active);
}
@Bindable
public boolean isActive(){
return isActive;
}
@Bindable("active")
public int getVisibility1(){
return isActive ? View.VISIBLE : View.GONE;
}
@Bindable("active")
public int getVisibility2(){
return isActive ? View.GONE : View.VISIBLE;
}
在OnCreateView
中分段设置视图模型。
现在的问题是,在加载片段时,它会同时显示两个容器一段时间,然后根据条件隐藏其中一个容器。在不通过代码对视图可见性进行硬编码的情况下,是否有任何解决方案可以删除此Flash?