我已经在我的项目中实现了数据绑定。我有一个特定的屏幕,在 include 标签中有两个嵌套布局。我无法以编程方式使用数据绑定更改包含布局的可见性。
但是,我已经通过布尔值实现了它,但我的问题是如何以编程方式设置包含标记的可见性。
我的xml:
<include
android:id="@+id/reg_email"
layout="@layout/custom_email"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<include
android:id="@+id/reg_phone"
layout="@layout/custom_phone"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Run Code Online (Sandbox Code Playgroud)
在活动中:当我尝试设置它时 - 它变成红色,这意味着它不会将其视为视图。
dataBinding.regPhone.setVisibility(View.GONE);
dataBinding.regEmail.setVisibility(View.VISIBLE);
Run Code Online (Sandbox Code Playgroud)