對於我的應用程序的用戶界面,我使用Transition
s和Fragment
s。在我的第一個Fragment
的onCreateView
函數中,我啓動了一個Transition
將顯示從第一個Scene
更改爲第二個Scene
。之後,當我點擊一個Button
時,我開始另一個Transition
顯示某種由第三個Scene
代表的「splashscreen」,並且在onTransactionEnd
中,我嘗試將Fragment
更改爲myView.postDelayed(new myRunnableForChangingFragment(),1000)
。轉換和片段
在調試模式下,我看到我的Runnable
已正確啓動,但新的Fragment
未替換第一個......但是,確實發生了一些情況:必須單擊後退按鈕上的兩次才能返回到我的第一個Fragment
。事實上,它似乎Fragment
被激活,但不可見...
任何想法,我怎麼能解決這個問題?
由於要求在第一個評論,這裏是我用來更改代碼的Fragment
:
fragment=new mySecondFragment();
transaction=getActivity().getFragmentManager().beginTransaction();
transaction.replace(R.id.Conteneur, fragment,"Fragment tag");
transaction.addToBackStack(null);
transaction.commit();
我可以添加該代碼從onTransitionEnd
作品完美地外推出。
爲「容器」中的XML文件:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/Conteneur" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> </LinearLayout>
用於第一和第二場景中的XML文件(唯一的區別;按鈕中的第一個設置爲不可見的代碼) :
<TextView android:id="@+id/TitreJeux" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginBottom="@dimen/MargeVerticaleBoutonsInterfaceJeux" android:lines="1" android:text="@string/app_name" android:textColor="#FFFF00" android:textSize="35sp" android:textStyle="bold" android:typeface="serif"/> <vd63.jeux.JeuAnimationRapide.BoutonInterface android:id="@+id/BoutonOptions" android:layout_width="wrap_content" android:layout_height="0dp" android:layout_gravity="center" android:layout_marginTop="@dimen/MargeVerticaleBoutonsInterfaceJeux" android:layout_weight="1" android:background="@drawable/bouton_jouer" android:text="@string/BoutonOptions" android:textColor="@color/CouleurTexteBoutons" android:textSize="25sp" android:typeface="serif"/>
的XML FLE的 「飛濺」 場景:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/EcranChargement" android:orientation="vertical" android:gravity="center" android:background="@drawable/fond_interface" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".JeuAnimationRapide"> <ImageView android:id="@+id/VD63" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/vd63"/> <ImageView android:id="@+id/Chargement" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/chargement"/>
我過渡從場景中的一個(按鈕不可見的,簡單Slide
)到場景2然後返回到場景1(Slide
再次)然後到「飛濺」場景(具有Fade
轉換)。
?請分享FragmentTransaction代碼? –
好的,問題解決了!我搞亂了不同的觀點和容器...... – Zelig63