使用viewbind时,如何在使用xml布局的自定义ViewGroup中使用呢
jqorz opened this issue · 4 comments
jqorz commented
自定义ViewGroup布局名称layout_empty_tip
,根标签使用了<merge>
,
声明了private val binding: LayoutEmptyTipBinding by viewbind()
但是运行报错了
java.lang.NoSuchMethodException: inflate [class android.view.LayoutInflater]
at java.lang.Class.getMethod(Class.java:2068)
at java.lang.Class.getMethod(Class.java:1690)
at com.hi.dhl.binding.ReflectExtKt.inflateMethod(ReflectExt.kt:17)
at com.hi.dhl.binding.viewbind.ViewGroupViewBinding.(ViewGroupViewBinding.kt:24)
看了下应该是反射没找到inflate方法
fun Class.inflateMethod() = getMethod(INFLATE_NAME, LayoutInflater::class.java)
但是不知道怎么解决
hi-dhl commented
- 检查一下有没有添加混淆
- 我已经添加了,在 ViewGroup 中使用
<merge>
,示例如下所示
jqorz commented
- 检查一下有没有添加混淆
- 我已经添加了,在 ViewGroup 中使用
<merge>
,示例如下所示
你好,demo和我描述的情况不太一致,我的自定义View的根布局就是merge标签,这样我的merge的Binding没有可以绑定的对象
hi-dhl commented
已经修复,请升级到 1.1.3 的版本,即可
- 当根布局是非 merge 标签,使用此方法进行初始化
val binding: LayoutViewCustomBinding by viewbind()
- 当根布局为 merge 标签,使用此方法进行初始化
val binding: LayoutViewCustomBinding by viewbind(this)
详细的 Demo 示例如下所示。
jqorz commented
已经修复,请升级到 1.1.3 的版本,即可
- 当根布局是非 merge 标签,使用此方法进行初始化
val binding: LayoutViewCustomBinding by viewbind()
- 当根布局为 merge 标签,使用此方法进行初始化
val binding: LayoutViewCustomBinding by viewbind(this)
详细的 Demo 示例如下所示。
感谢作者