2016-12-15 105 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"/> 

亲切的问候!