温馨提示:本文翻译自stackoverflow.com,查看原文请点击:android - How to use View Binding on custom views
android android-custom-view android-viewbinding

android - 如何在自定义视图上使用视图绑定

发布于 2020-05-16 14:03:38

视图绑定随v3.6发布。

文件:https//developer.android.com/topic/libraries/view-binding

我的问题是,如何将视图绑定与自定义视图一起使用。Google文档仅显示了用例显示的“活动”和片段。

我试过了,但是什么也没显示。

LayoutInflater inflater = LayoutInflater.from(getContext());

然后,我用了这个,但还是没有运气。

LayoutInflater inflater = (LayoutInflater)
            getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

我猜想,也许我没有针对我的视图设置正确的布局填充器,但不确定。

查看更多

提问者
Emi Raz
被浏览
7
Androiderson 2020-04-14 06:11

只需告知根,以及是否要附加到根

init { // inflate binding and add as view
    binding = ResultProfileBinding.inflate(LayoutInflater.from(context), this, true)
}