2014-11-08 158 views
1

動畫片段事務處理時出現此錯誤。未知動畫名稱:翻譯

片段A的xml:

<FrameLayout 
android:id="@+id/relative" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
xmlns:android="http://schemas.android.com/apk/res/android"> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:padding="15dp" 
android:background="#009688"> 

<RelativeLayout 
    android:layout_weight="0.5" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:id="@+id/linear"> 

    <TextView 
     android:layout_marginTop="35dp" 
     android:id="@+id/mission" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="MISSION" 
     android:textColor="#ffffff" 
     android:textSize="70dp" 
     android:gravity="center_horizontal"/> 

    <TextView 
     android:layout_below="@+id/mission" 
     android:id="@+id/notimpossible" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="NOT IMPOSSIBLE" 
     android:textColor="#ffffff" 
     android:textStyle="bold" 
     android:textSize="35dp" 
     android:gravity="center_horizontal"/> 

</RelativeLayout> 

<RelativeLayout 
    android:padding="10dp" 
    android:layout_weight="0.5" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_below="@+id/linear"> 

    <TextView 
     android:id="@+id/random_main" 
     android:textSize="20dp" 
     android:textColor="@color/white" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"/> 

</RelativeLayout> 


<TextView 
    android:id="@+id/ahead" 
    android:clickable="true" 
    android:layout_marginBottom="35dp" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:text="Go Ahead! " 
    android:textSize="23dp" 
    android:textColor="@drawable/text_focus_white" 
    android:layout_marginRight="8dp" 
    android:layout_gravity="right"/> 


</LinearLayout> 
</FrameLayout> 

片段B的xml:

<?xml version="1.0" encoding="utf-8"?> 

<FrameLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#cddc39"> 

代碼從片段A tranaction到片段B:

fragB frag = new fragB(); 
    FragmentManager fm = getFragmentManager(); 
    FragmentTransaction ft = fm.beginTransaction(); 
    ft.addToBackStack("wTF"); 
    ft.setCustomAnimations(R.anim.slide_out_to_right, R.anim.slide_in_from_right); 
    ft.replace(R.id.main,fragB); 
    ft.commit(); 

</FrameLayout> 

而這裏是動畫個XML

Slide_in_from_right:

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

這裏是slide_out_to_right:

<?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:fromYDelta="0%" android:toYDelta="0%" 
    android:duration="700" /> 
</set> 
+0

downvoters介意評論? – 2014-11-08 06:20:58

回答

7

沒有,你可以使用translateActivities而不是fragment。您需要爲fragment使用objectAnimator

看看在這個問題上的第一個答案,它的工作:

Android FragmentTransaction Custom Animation (Unknown Animator Name: Translate)

+0

我在某處閱讀使用framelayout的地方,翻譯屬性可以工作,並且該答案有超過100個upvotes。 – 2014-11-08 06:19:59

+0

@HirakChhatbar真的嗎?對不起,我不知道那..但你仍然有你的錯誤,我不知道如何解決它與框架佈局。 – 2014-11-08 06:45:45

+0

謝謝你的任何方式...我決定留在objectAnimator(y) – 2014-11-08 07:06:01