2017-07-15 7 views
0

私のアプリのUIでは、TransitionFragmentを使用します。最初のFragmentonCreateView機能では、最初にSceneからSceneにディスプレイを変更するためにTransitionを起動します。その後、Buttonをクリックすると、別のTransitionが表示され、第3のSceneで表される「スプラッシュスクリーン」が表示され、そのうちonTransactionEndにはFragmentmyView.postDelayed(new myRunnableForChangingFragment(),1000)に変更しようとします。トランジションとフラグメント

デバッグモードでは、Runnableが正しく起動されていますが、新しいFragmentは最初のものに取って代わるものではありません...しかし、何かが起こりました。私は戻るボタンで2回クリックしなければなりません。最初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"/> 

I推移シーン1から(目に見えないボタン、シンプルSlide)シーン2へシーン1(Slide)、次に「スプラッシュ」シーン(Fadeトランジション)。

+0

を追加する必要はありませんがFragmentTransactionコードを共有していただけますか? –

+0

問題は解決しました。私は、さまざまなビューとコンテナを台無しにしていた... – Zelig63

答えて

1

フラグメント1からフラグメント2に切り替えると、以下のコードが使用されます。

Fragment fragment = SearchActivity.newInstance(context); 
String tag = fragment.toString(); 
getFragmentManager().beginTransaction() 
.addToBackStack(tag)  
.replace(R.id.fragment, new SearchActivity()) 
.commit(); 

使用addToBackStackあなたはbackpressに再び戻ってこのフラグメントに来てほしいときそうあなたがaddTobackstack

関連する問題