I have two scenes:
Scene1.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
style="@style/AppTheme.TopPanel"
android:id="@+id/top_panel"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</RelativeLayout>
<RelativeLayout
style="@style/AppTheme.Panel"
android:id="@+id/bottom_panel"
android:layout_width="match_parent"
android:layout_height="72dp">
</RelativeLayout>
</LinearLayout>
Scene2.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
style="@style/AppTheme.TopPanel"
android:id="@+id/top_panel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
</RelativeLayout>
<RelativeLayout
style="@style/AppTheme.Panel"
android:id="@+id/bottom_panel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
</RelativeLayout>
</LinearLayout>
我还有一个包含唯一Fragment的活动。当程序开始时,我将这个Fragment替换为我的FirstFragment类。里面有一个按钮。当你点击它时,会执行以下代码:
@Override
public void onClick(View v) {
ChangeBounds transitions = new ChangeBounds();
transition.addListener(new Transition.TransitionListener() {
//Other overrides...
@Override
public void onTransitionEnd(Transition transition) {
SecondFragment fragment = new SecondFragment();
getFragmentManager().beginTransaction()
.replace(R.id.fragment_container, fragment)
.addToBackStack(null)
.commit();
}
//Other overrides...
});
ViewGroup sceneRoot = (ViewGroup) getView();
Scene from = Scene.getSceneForLayout(sceneRoot, R.layout.scene1, getActivity());
Scene to = Scene.getSceneForLayout(sceneRoot, R.layout.scene2, getActivity());
from.enter();
TransitionManager.beginDelayedTransition(sceneRoot, transitions);
to.enter();
}
但是过渡并没有发生。它开始了,下一刻就结束了。这里是实际效果:
我的错误在哪里?
transitions
值。 - Maveňツ