Android的DataBinding是否与Transitions / Scenes框架一起使用?

时间:2016-03-14 19:56:25

标签: android data-binding android-transitions android-databinding

Android DataBinding库是否适用于Transitions framework

        Scene scene = Scene.getSceneForLayout(this, R.layout.creditcardentryview_scene2_expanded, this.getContext());
        TransitionManager.go(scene);
        scene2Binding = CreditcardentryviewScene2ExpandedBinding.bind(this);

尝试上述代码会引发此错误:view tag isn't correct on view:null

2 个答案:

答案 0 :(得分:8)

您应该在创建场景之前绑定布局:

CreditcardentryviewScene2ExpandedBinding binding = CreditcardentryviewScene2ExpandedBinding.inflate(getLayoutInflater(), this, false);
Scene scene = new Scene(this, binding.getRoot());
TransitionManager.go(scene);

bind(this)失败,因为this不是绑定视图。 this是场景根!所以你也可以这样做:

Scene scene = Scene.getSceneForLayout(this, R.layout.creditcardentryview_scene2_expanded, this.getContext());
TransitionManager.go(scene);
scene2Binding = CreditcardentryviewScene2ExpandedBinding.bind(this.getChildAt(0));

答案 1 :(得分:-1)

您必须使用DataBindingUtil.inflate()

自行填充视图

并使用膨胀的视图构建场景。 https://developer.android.com/reference/android/transition/Scene.html#Scene(android.view.ViewGroup,android.view.ViewGroup)

.bind(this)仍然失败,因此您必须手动管理生成的绑定。