因此,我们试图制作一个动画,在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);
}
编辑我的代码片段清理了一些变量名。
你怎么称呼这个方法? circularReveal(fab,toolbar); ?因为您在名为工具栏的视图上应用translateAnimation。 –
该方法是从 onClickListener调用的,该onClickListener在片段onCreatView()上的Fab上设置。 –