2016-12-15 137 views
0

我試圖在進行片段事務時放入幻燈片並滑出正確的動畫。動畫正常工作。但是,在製作片段動畫時,我得到了一個白色屏幕。我厭倦了谷歌給出的所有可能的解決方案。但是,他們都沒有工作。這是我目前正在做的。動畫片段出現白色屏幕

/** enter_from_left.xml **/ 

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shareInterpolator="false"> 
    <translate 
     android:fromXDelta="-100%" android:toXDelta="0%" 
     android:duration="500"/> 
</set> 

/** enter_from_right.xml **/ 

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shareInterpolator="false"> 
    <translate 
     android:fromXDelta="100%" android:toXDelta="0%" 
     android:duration="500" /> 
</set> 


/** exit_to_left.xml **/ 

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shareInterpolator="false"> 
    <translate 
     android:fromXDelta="0%" android:toXDelta="-100%" 
     android:duration="500"/> 
</set> 

/** exit_to_right.xml **/ 

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shareInterpolator="false"> 
    <translate 
     android:fromXDelta="0%" android:toXDelta="100%" 
     android:duration="500" /> 

</set> 

在容器更換片段:

public static void replaceAndAddToBackStack(final FragmentActivity activity, final int containerId, 
               final Fragment fragment, String tag, int enter, int exit, int popEnter, int popExit) { 
     try { 
      FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction(); 
      transaction.setCustomAnimations(enter, exit, popEnter, popExit); 
      transaction.replace(containerId, fragment); 
      transaction.addToBackStack(tag); 
      transaction.commitAllowingStateLoss(); 
     } catch (IllegalStateException e) { 
      e.printStackTrace(); 
     } 
    } 

其中enter, exit, popEnter, popExit是指 - >R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right

當我申請鉻自定義標籤相同的過渡,該過渡是非常流暢。沒有白色的屏幕。爲什麼白色屏幕只出現在片段交易中。

在此先感謝

回答

0

我有同樣的問題。嘗試將透明背景更改爲您的framelayout。

<FrameLayout 
    android:id="@+id/fragmentContainer" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#00000000"/> 

親切的問候!