我有一个包含2个ViewStubs的布局.它们的定义如下:
android:id="@+id/top_divider_stub"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inflatedId="@+id/top_divider_layout"
android:layout="@layout/include_line_separator_horizontal"/>
android:id="@+id/bottom_divider_stub"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inflatedId="@+id/bottom_divider_layout"
android:layout="@layout/include_line_separator_horizontal"/>
在我的适配器中,我试图通过DataBinding库生成的ViewDataBinding访问ViewStub,在我的例子中是TitleBinding.尝试执行以下操作会导致错误.
TitleBinding binding = DataBindingUtil.bind(view);
ViewStub topDividerStub = binding.topDividerStub;
ViewStub bottomDividerStub = binding.bottomDividerStub;
我收到此错误,应用程序无法编译.
Error:(31,50) error: incompatible types: ViewStubProxy cannot be converted to ViewStub
我通过将变量设置为类型ViewStubProxy来解决它,允许它进行编译,但是提供了不兼容的类型语法突出显示错误.如果可能的话,我想知道这样做的正确方法.
这有效……
ViewStubProxy topDividerStub = binding.topDividerStub;
ViewStubProxy bottomDividerStub = binding.bottomDividerStub;
导致