2016-12-13 3 views
1

FABを消す前にFABを移動し、ツールバーを開くアニメーションを作成しようとしています。問題は、TranslationAnimationを実行してFABが消えた後、画面外にスライドするときです。 fromxDeltaとfromDeltaは、私がそれらを期待する方法を実行することはありません。翻訳アニメーションは、所属する場所ではなく画面から開始します

私が間違っていることを指摘したり、この呼び出しの仕組みを理解するのに役立ちますか?

private void circularReveal(View toolbar, View fab) { 
    final View view1 = toolbar; 

    // get the center for the clipping circle 
    int cx = (toolbar.getLeft() + toolbar.getRight())/2; 
    int cy = (toolbar.getTop() + toolbar.getBottom())/2; 

    // get the final radius for the clipping circle 
    int finalRadius = Math.max(toolbar.getWidth(), toolbar.getHeight()); 

    // create the animator for this view (the start radius is zero) 
    final SupportAnimator anim = ViewAnimationUtils.createCircularReveal(toolbar, cx, cy, 0, finalRadius); 
    //todo create an animation to move the fab. 

    TranslateAnimation translateAnimation = new TranslateAnimation(Animation.ABSOLUTE, 0f, 
                   Animation.ABSOLUTE , -100f, 
                   Animation.ABSOLUTE , 0f, 
                   Animation.ABSOLUTE , -100f); 
    translateAnimation.setDuration(2000L); 
    translateAnimation.setFillAfter(true); 
    Animation.AnimationListener animationListener = new Animation.AnimationListener() { 

     @Override 
     public void onAnimationStart(Animation animation) { 

     } 

     @Override 
     public void onAnimationEnd(Animation animation) { 
      view1.setVisibility(View.VISIBLE); 
      anim.start(); 
     } 

     @Override 
     public void onAnimationRepeat(Animation animation) { 

     } 
    }; 
    translateAnimation.setAnimationListener(animationListener); 
    fab.startAnimation(translateAnimation); 
} 

EDIT私は、コードスニペットでは、いくつかの変数名をクリーンアップ。

+0

どうやってこのメソッドを呼び出しますか? circularReveal(ファブ、ツールバー); ?これは、名前付きのツールバーであるビューにtranslateAnimationを適用するためです。 –

+0

このメソッドは、フラグメントonCreatView()でFabに設定されているonClickListenerの から呼び出されます。 –

答えて

1

が消える前にFABを移動し、ツールバーを開くアニメーションを作成しようとしています。

あなたのコードは逆です。ビューに「ツールバー」という名前のTranslateAnimationを適用し、FloatingActionButtonに円形のRevealを使用しているようです。

とにかく私はあなたがこのような何かを達成しようとしていると思います:

private void circularReveal(final View view, View toolbar) { 

    // get the center for the clipping circle 
    int cx = (toolbar.getLeft() + toolbar.getRight())/2; 
    int cy = (toolbar.getTop() + toolbar.getBottom())/2; 

    // get the final radius for the clipping circle 
    int finalRadius = Math.max(toolbar.getWidth(), toolbar.getHeight()); 

    // create the animator for this view (the start radius is zero) 
    final Animator anim = ViewAnimationUtils.createCircularReveal(toolbar, cx, cy, 0, finalRadius); 

    view.animate() 
      .translationX(-100) 
      .translationY(-100) 
      .setDuration(2000) 
      .setListener(new Animator.AnimatorListener() { 
       @Override 
       public void onAnimationStart(Animator animation) { 

       } 

       @Override 
       public void onAnimationEnd(Animator animation) { 
        view.setVisibility(View.INVISIBLE); // set this to INVISIBLE if you want your FAB to dissapear 
        anim.start(); 
       } 

       @Override 
       public void onAnimationCancel(Animator animation) { 

       } 

       @Override 
       public void onAnimationRepeat(Animator animation) { 

       } 
      }); 

} 

これは少し左にして、ツールバーを明らかにし、FAB。消える前までFABを移動します。

最初にFABを使用し、ツールバーを2番目のパラメータとして使用してこのメ​​ソッドを呼び出します。

ViewPropertyAnimatorビューの実際の位置を変更しながら、私は、TranslateAnimationを残し、TranslateAnimationが本当にビューを移動しますが、画面上の画素のみされていないため、ViewPropertyAnimatorを使用。 TranslateAnimationの問題は、FABがあった元の位置をクリックすることができ、FAB OnClickListenerを引き続きトリガーするということです。

+0

ありがとう私はそれらの変数名をクリーンアップしました。私はあなたの例のようにViewPropertyAnimatorを試してみました。そして、2秒後に新しい場所に再び現れるように、画面からファブが消えました。 –

+0

私はフラグメントレイアウトxmlの2つのxml親でandroid:animateLayoutChanges = "true"という属性を設定しなければなりませんでした。アニメーションが正しく表示されたら、ご協力いただきありがとうございます。 –

関連する問題