4

Android 的DataBinding库是否可以与Transitions 框架一起使用?

        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

4

2 回答 2

11

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

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));
于 2016-03-16T11:32:22.923 回答
0

您必须自己膨胀视图DataBindingUtil.inflate()

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

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

于 2016-03-15T17:45:42.937 回答