我有兩個場景:Android的過渡不起作用
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>
而且我也有一個包含唯一的活動分段。當程序開始時,我用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();
}
但是轉換沒有發生。它開始,下一刻結束。下面是在行動:
哪裏是我的錯?
調試並檢查TransitionManager.beginDelayedTransition(getView(),transitions)中是否有'transitions'的值;這條線。 – Gattsu 2015-03-03 09:03:43