我想知道如何在替换片段时制作圆形的显示动画。
我正在使用此代码替换我的片段:
getFragmentManager()
.beginTransaction()
.replace(R.id.mission_detail_appointment_container, new AppointmentDeclineFragment())
.commit();
我得到了以下代码来进行循环显示动画:
Animator anim = ViewAnimationUtils.createCircularReveal(appointmentContainer, (int)motionEventX, (int)motionEventY, 0, finalRadius);
anim.start();
替换片段时,有什么方法可以启动动画器吗?我刚刚看到了setCustomAnimation方法,但是它使用int资源作为参数,然后转到Animator对象。
谢谢你的帮助
我终于找到了解决方法。对于那些可能需要它的人,这就是我决定在片段中实施循环显示动画的方式。
通过在片段的onCreateView方法中添加onLayoutChangeListener:
view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
v.removeOnLayoutChangeListener(this);
int cx = getArguments().getInt(MOTION_X_ARG);
int cy = getArguments().getInt(MOTION_Y_ARG);
int width = getResources().getDimensionPixelSize(R.dimen.fragment_appointment_width);
int height = getResources().getDimensionPixelSize(R.dimen.fragment_appointment_height);
float finalRadius = Math.max(width, height) / 2 + Math.max(width - cx, height - cy);
Animator anim = ViewAnimationUtils.createCircularReveal(v, cx, cy, 0, finalRadius);
anim.setDuration(500);
anim.start();
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句