2013-07-20 18 views
61

私のフラグメントで作業するカスタムアニメーションを取得しようとしています。Android FragmentTransactionカスタムアニメーション(不明なアニメーター名:翻訳)

私はオンラインチュートリアルに従ってきましたが、私は以下のエラーになってきました:

java.lang.RuntimeException:不明なアニメーターの名前を:アニメーション

XMLを変換するには、以下の通りです:

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

Javaファイルを以下に示します。

public void goCategory(View v) {   
    FragmentTransaction ft = fm.beginTransaction();  
    ft.setCustomAnimations(R.animator.anim_in_left, R.animator.anim_out_left);    
    ft.show(fragment); 
    ft.commit(); 
} 

他のスレッドの解決方法を理解できません。 誰かが私のためにそれを愚かにすることができたら、私は本当にそれを感謝します。

おかげ

+0

サポートライブラリのバージョンのFragmentでアニメーションを使用している場合は、問題がある可能性があります。 –

答えて

92

それはあなたがオブジェクトのアニメーターを使用する必要があり、動作しません

アニメーター/ slide_in_left.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" > 

    <objectAnimator 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:duration="500" 
     android:propertyName="x" 
     android:valueFrom="1000" 
     android:valueTo="0" 
     android:valueType="floatType" /> 

</set> 

アニメーター/ slide_out_right.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" > 

    <objectAnimator 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:duration="500" 
     android:propertyName="x" 
     android:valueFrom="0" 
     android:valueTo="-1000" 
     android:valueType="floatType" /> 

</set> 

クラスサブカテゴリ

public View onCreateView(LayoutInflater inflater, ViewGroup container, 
       Bundle savedInstanceState) { 
      // TODO Auto-generated method stub 
      // return super.onCreateView(inflater, container, savedInstanceState); 

      View view = (ViewGroup) inflater.inflate(R.layout.product_frame, null); 
      getFragmentManager().beginTransaction() 
        .replace(R.id.sub_header, new Sub_Header()).commit(); 
      getFragmentManager() 
        .beginTransaction() 
        .setCustomAnimations(R.animator.slide_in_left, 
          R.animator.slide_out_right, 0, 0) 
        .replace(R.id.product_frame, new Sub_Catagory_Grid()).commit(); 

      view.getWidth(); 
      return view; 

     } 
+7

なぜ機能しないのですか?あなたは説明できますか? –

+0

何が問題なのですかここに投稿する私はあなたの質問を理解していません。 –

+2

彼はOPの解決策がうまくいかず、明確化を求める声明を参照しています。 – Tom

106

恐らく2つのapiを混合しています。 2例があります。

  • サポートv4のフラグメントを使用して3.0 または下にターゲットした場合:あなたは、古いアニメーションAPIを使用する必要があり、それは、あなたが使用しているものです(彼らはアニメーション/に行き、そしてありますR.anim.thing

  • あなたはネイティブの断片を使用して3.0 上にターゲットにしている場合:あなたは、新しいアニメーションAPIを使用する必要があり、それは、ObjectAnimators(彼らはアニメーターに入る/及びR.animator.thingある)です。

+1

ドキュメントで、ネイティブフラグメントにオブジェクトアニメーターを使用する必要があると言いますか? – kmdupr33

+0

私は両方のApiのソースコードをチェックし、すべてのアニメーションxmlがres/animフォルダに入るはずであること、アニメータ/ –

0

@ minivacは2つのAPIを混合しています。フラグメント取引にカスタムアニメーションを追加する方法については、AndroidトレーニングガイドのDisplay Card Flip Animationsの例をご覧ください。それはあなたの問題を正確に解決します。

関連する問題