2017-03-12 18 views
0

を明らかにする:遅れ円は私がボタンを押したときに、私はこのアニメーションを使用していますアニメーション

void circleAnimationEnter(final View view, final View view2) { 


    // get the center for the clipping circle 
    int cx = Math.round(view2.getX() + view2.getWidth()/2); 
    int cy = Math.round(view2.getY() - view2.getHeight()/2); 

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

    // create the animator for this view (the start radius is zero) 
    Animator anim; 
    Animation animation; 
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { 
     anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius); 
     // make the view visible and start the animation 
     view.setVisibility(View.VISIBLE); 
     anim.setDuration(1000); 
     anim.setInterpolator(new AccelerateInterpolator()); 
     anim.start(); 
    } else { 
     view.setVisibility(View.VISIBLE); 
     view.animate() 
       .translationX(0) 
       .setDuration(500) 
       .setListener(new AnimatorListenerAdapter() { 
        @Override 
        public void onAnimationEnd(Animator animation) { 
         super.onAnimationEnd(animation); 
        } 
       }); 
    } 
} 

View1をは/ショーを隠すための図であり、VIEW2は押しボタンです。

同じアニメーション(いくつかの変更はあまりありません)は、同じボタンを押して再び表示を変更すると非表示になります。

問題は、最初にボタンを押したときにアニメーションが遅れている(ビューがサークルアニメーションで表示されています)が、次回はアニメーションでビューの視認性が変わります、表示して非表示にする)完全に。

CollapsingToolbarLayoutを使用していますが、これは問題になる可能性がありますか?

遅れていますか?またはAndroidが正しくXとYを取得していないとき初めてですか?

ご協力いただきありがとうございました。ご迷惑をおかけして申し訳ありません。

EDIT:

問題は、CXとCYの値を得ることについてです。

Display display = getActivity().getWindowManager().getDefaultDisplay(); 
    Point size = new Point(); 
    display.getSize(size); 
    int width = size.x; 
    int height = size.y; 

    // get the center for the clipping circle 
    cx = Math.round(width-width*10/100); 
    cy = Math.round(height-height*38/100); 

    initialRadius = Math.max(width*3/2, height*3/2); 
    finalRadius = initialRadius; 

私のアニメーションはもう遅れが、問題はツールバーが折りたたままたは拡張された私は、画面サイズを取得していますので...(私は、このことを理解していない場合はCXとCYが変化しているということですされていませんので、私のCXとCYは私が解決

+0

あなたは、 'cx'は' CollapsingToolbarLayout'の状態(展開/折りたたみ)によって異なると主張していますか? – azizbekian

+0

@azizbekian私の答えをチェック! – Dahnark

答えて

0

)...常に同じである必要があり、問題はそのコードで

final AppBarLayout appBarLayout = (AppBarLayout) getActivity().findViewById(R.id.app_bar); 
    appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { 
     @Override 
     public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { 
      // get the center for the clipping circle 
      cx = Math.round(floatingActionButton.getX() + floatingActionButton.getWidth()/2); 

      boolean fullyExpanded = (appBarLayout.getHeight() - appBarLayout.getBottom()) == 0; 

      if (!fullyExpanded) { 
       cy = Math.round(floatingActionButton.getY() - floatingActionButton.getHeight()); 
      } else { 
       cy = Math.round(floatingActionButton.getY() + floatingActionButton.getHeight()/2) - appBarLayout.getHeight(); 
      } 

      initialRadius = Math.max(width * 3/2, height * 3/2); 
      finalRadius = initialRadius; 
     } 
    }); 

...それが崩壊したアプリバーだったか、私が得ましたfabボタンcx/cyを完全に追加しました。サークルアニメーションの高さ/幅の問題を避けるため、半径に3/2を追加しました。完璧です。

関連する問題