2016-10-23 20 views
2

ボタンをクリックしたときに表示されるフラグメントにアニメーションを追加しようとしています。ここでそれを呼び出すAndroid:フラグメントをスライドさせるには?

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

    <translate xmlns:android="http://schemas.android.com/apk/res/android" 
     android:duration="@android:integer/config_mediumAnimTime" 
     android:fromYDelta="50.0%p" 
     android:interpolator="@android:anim/decelerate_interpolator" 
     android:toYDelta="30" /> 
</set> 

up.xml

フラグメントレイアウト

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentBottom="true" 
    android:orientation="vertical" > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="50dp" 
     android:background="@color/wallet_holo_blue_light" 
     android:layout_gravity="center" 
     android:text="This is a fragmentt layout" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" /> 

</RelativeLayout> 

スライド:

public void onClick(View view) { 

      if(view == button){ 

     FragmentManager fragmentManager = getFragmentManager(); 
     FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); 
     FragmentOnMap hello = new FragmentOnMap(); 

     fragmentTransaction.add(R.id.fragment_container, hello, "HELLO"); 
     fragmentTransaction.setCustomAnimations(R.animator.slide_up,0); 
     fragmentTransaction.commit(); 
    } 


} 

Android Fragments and animationが上下にスライドする方法を示して、私だけの断片をアニメーション化しますアップ。したがって、私の質問、setcustomanimation()関数の第2引数の

私はコミットの直前にfragmentTransaction.setCustomAnimations()を使ってみましたが、助けにはなりませんでした。

下部に表示されますが、トランジション効果はありません。 ガイダンスは役に立ちます。 ありがとうございました

+2

[Androidのかけらやアニメーション]の可能な重複(http://stackoverflow.com/questions/ 4817900/android-fragments-and-animation) – jakubbialkowski

答えて

1

より前にaddとする必要があります。

また、アプリケーションの代わりにフラグメント(v4)のサポートライブラリを使用し、フラグメントを使用するときにgetSupportFragmentManagerを呼び出してコードのすべての部分を修正する必要があるため、コードに問題があります。サポートライブラリを使用してください。

あなたはこれを変更したくない場合は、あなたがslide_upアニメーションのために、このコードを取ることができますが:

<?xml version="1.0" encoding="utf-8"?> 
<objectAnimator 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:interpolator="@android:anim/accelerate_decelerate_interpolator" 
    android:propertyName="translationY" 
    android:valueType="floatType" 
    android:valueFrom="1280" 
    android:valueTo="0" 
    android:duration="@android:integer/config_mediumAnimTime"/> 
+0

setcustomanimationの第2引数は何ですか? setCustomAnimation(R.id.slideup ,?) – AIS

+0

fragmentTransaction.setCustomAnimations(R.animator.slide_up、0);サポートライブラリを使用している場合はR.anim.slide_upです。 –

+0

私の編集コードを参照してください。アニメートしませんでした。あなたのslide_upを使用しました。断片はちょうど現れる。滑り効果はありません。 – AIS