2016-12-13 5 views
1

그래서 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); 
} 

편집 나는 코드에 일부 변수 이름을 청소.

+0

어떻게이 방법을 부릅니까? circularReveal (팹, 툴바); ? 왜냐하면 당신은 translateAnimation을 당신의 View라는 이름의 toolbar에 적용하기 때문입니다. –

+0

메서드는 에서 호출되며, onClickListener는 onCreatView()의 조각에서 Fab에 설정됩니다. –

답변

1

가 사라지기 전에 FAB을 움직이는 애니메이션을 만들고 툴바를 엽니 다.

코드는 다른 방향으로 읽습니다. 뷰에 'TranslateAnimation'이라는 이름의 '도구 모음'을 적용하고 FloatingActionButton에 Circular 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를 먼저 사용하고 ToolBar를 두 번째 매개 변수로 사용하여이 메서드를 호출합니다.

은 내가 TranslateAnimation을 떠나 ViewPropertyAnimator는보기의 실제 위치를 변경하면서 TranslateAnimation 정말, 화면의보기 만 픽셀을 이동하지 않기 때문에 ViewPropertyAnimator을 사용했다. TranslateAnimation의 문제점은 FAB이 있던 이전 위치를 계속 클릭 할 수 있으며 여전히 FAB OnClickListener를 트리거한다는 것입니다.

+0

감사합니다. 해당 변수 이름을 정리했습니다. 귀하의 예제에서 ViewPropertyAnimator를 시험해 보았고 2 초 후에 새로운 위치에 다시 나타나기 위해 화면에서 팹을 사라지게했습니다. –

+0

그래서 조각 레이아웃 xml의 두 xml 부모에서 android : animateLayoutChanges = "true"속성을 설정해야했습니다. 일단 내가 그 애니메이션이 올바르게 나타났다. 당신의 도움을 주셔서 감사합니다. –