使用多个 viewolder 和数据绑定库实现 recyclerview
Implementing a recyclerview with multiple viewolder and data binding library
我正在尝试将 数据绑定库 与 recyclerview
多个查看器(具有共享元素) 一起使用。
我尝试了涉及转换和泛型的解决方案。都没有用。
有没有办法将不同的 ViewDataBinding
类 与 link 相似的 xml
布局关联起来,使它们具有兄弟关系?
或者,有没有办法在xml
中进行继承?我认为由于 ViewDataBinding
对象(部分)由 xml
生成,也许父和子 xml
布局可以产生预期的效果?
请务必阅读我下面的评论以了解已实施的解决方案。我将其标记为正确的,因为它最终让我得到了正确的答案
-乔尔
希望我理解你的问题。
考虑下面的片段。
parent_xml.xml
<layout>
<FrameLayout
....
...
>
<!-- including child -->
<include
android:id="@+id/included"
layout="@layout/child_xml" />
</FrameLayout>
</layout>
child_xml.xml
<layout>
<View
android:id="@+id/child_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</layout>
您可以使用..访问子视图
ParentXmlBinding mBinding = DataBindingUtil.inflate(... reference of parent_xml);
mBinding.included.childView.(... Access view method here); // Referring child view
我回答你的问题了吗?
我正在尝试将 数据绑定库 与 recyclerview
多个查看器(具有共享元素) 一起使用。
我尝试了涉及转换和泛型的解决方案。都没有用。
有没有办法将不同的 ViewDataBinding
类 与 link 相似的 xml
布局关联起来,使它们具有兄弟关系?
或者,有没有办法在xml
中进行继承?我认为由于 ViewDataBinding
对象(部分)由 xml
生成,也许父和子 xml
布局可以产生预期的效果?
请务必阅读我下面的评论以了解已实施的解决方案。我将其标记为正确的,因为它最终让我得到了正确的答案 -乔尔
希望我理解你的问题。
考虑下面的片段。
parent_xml.xml
<layout>
<FrameLayout
....
...
>
<!-- including child -->
<include
android:id="@+id/included"
layout="@layout/child_xml" />
</FrameLayout>
</layout>
child_xml.xml
<layout>
<View
android:id="@+id/child_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</layout>
您可以使用..访问子视图
ParentXmlBinding mBinding = DataBindingUtil.inflate(... reference of parent_xml);
mBinding.included.childView.(... Access view method here); // Referring child view
我回答你的问题了吗?