目前,我正在尝试实现类似于Google Inbox的RecyclerView
行为,并且对邮件打开动画非常好奇。
我的问题是:他们是如何做到的?我的意思是,他们使用了哪种方法?他们使用了ItemAnimator.dispatchChangeStarting()
并将其高度更改为填充父级吗?还是其他的方法?如果确实是这样,他们是如何通过拉手势将其关闭而使底层RecyclerView
元素略微可见。
有人可以帮忙指向一些库或代码片段/示例吗?
目前,我正在尝试实现类似于Google Inbox的RecyclerView
行为,并且对邮件打开动画非常好奇。
我的问题是:他们是如何做到的?我的意思是,他们使用了哪种方法?他们使用了ItemAnimator.dispatchChangeStarting()
并将其高度更改为填充父级吗?还是其他的方法?如果确实是这样,他们是如何通过拉手势将其关闭而使底层RecyclerView
元素略微可见。
有人可以帮忙指向一些库或代码片段/示例吗?
public class CreateAnimationView {
private static int contador;
Integer colorFrom = R.color.myAccentColor;
Integer colorTo = Color.RED;
public static AnimatorSet createAnimation(View view) {
ObjectAnimator fadeOut = ObjectAnimator.ofFloat(view, "alpha",
0f);
fadeOut.setDuration(300);
ObjectAnimator mover = ObjectAnimator.ofFloat(view,
"translationX", -500f, 0f);
mover.setDuration(400);
ObjectAnimator fadeIn = ObjectAnimator.ofFloat(view, "alpha",
0f, 1f);
fadeIn.setDuration(300);
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.play(mover);
animatorSet.start();
return animatorSet;
}
... more animations methods.
}
在您的RecyclerViewAdapter中:
@Override
public void onBindViewHolder(ViewHolder viewHolder, int position) {
GruposCardView gruposCardView = gruposCardViews.get(position);
CreateAnimationView.createAnimationRandom(viewHolder.cardView);
...}
如果不是在RecyclerView中,您可以传递一个布局并使用此动画,或从此创建一个动画。
public static AnimatorSet createAnimationCollapseXY(View view) {
ObjectAnimator scaleXOut = ObjectAnimator.ofFloat(view, "scaleX", 1f, 0f).setDuration(400);
ObjectAnimator scaleXIn = ObjectAnimator.ofFloat(view, "scaleX", 0f, 1f).setDuration(300);
ObjectAnimator scaleYOut = ObjectAnimator.ofFloat(view, "scaleY", 1f, 0f).setDuration(400);
ObjectAnimator scaleYIn = ObjectAnimator.ofFloat(view, "scaleY", 0f, 1f).setDuration(300);
ObjectAnimator rotateClockWise = ObjectAnimator.ofFloat(view, "rotation", 0f, 360f).setDuration(400);
ObjectAnimator rotateCounterClockWise = ObjectAnimator.ofFloat(view, "rotation", 0f, -360f).setDuration(400);
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(scaleXIn, scaleYIn);
//animatorSet.setStartDelay(1200);
animatorSet.start();
return animatorSet;
}