【发布时间】:2015-03-31 09:03:42
【问题描述】:
请查看此页面 -> http://frogermcs.github.io/InstaMaterial-concept-part-5-like_action_effects/
我只是在学习 InstaMaterial 的源代码。我几乎理解了大多数代码。但我不明白 FeedAdapter 中的 "likeAnimations" 变量代表什么。
我知道这是一个哈希映射。我认为这是为了防止重复呼叫。虽然不是……
谁能解释一下这个变量的用途?
FeedAdapter 的完整源码在这里 -> https://github.com/frogermcs/InstaMaterial/blob/master/app/src/main/java/io/github/froger/instamaterial/ui/adapter/FeedAdapter.java
如有任何进展,我将不胜感激。
在会员领域。
private final Map<RecyclerView.ViewHolder, AnimatorSet> likeAnimations = new HashMap<>();
在“animatePhotoLike”方法中。
private void animatePhotoLike(final CellFeedViewHolder holder) {
if (!likeAnimations.containsKey(holder)) {
holder.vBgLike.setVisibility(View.VISIBLE);
holder.ivLike.setVisibility(View.VISIBLE);
holder.vBgLike.setScaleY(0.1f);
holder.vBgLike.setScaleX(0.1f);
holder.vBgLike.setAlpha(1f);
holder.ivLike.setScaleY(0.1f);
holder.ivLike.setScaleX(0.1f);
AnimatorSet animatorSet = new AnimatorSet();
// It puts 'holder' and 'AnimatorSet' into this HashMap before starting animations.
likeAnimations.put(holder, animatorSet);
ObjectAnimator bgScaleYAnim = ObjectAnimator.ofFloat(holder.vBgLike, "scaleY", 0.1f, 1f);
bgScaleYAnim.setDuration(200);
bgScaleYAnim.setInterpolator(DECCELERATE_INTERPOLATOR);
ObjectAnimator bgScaleXAnim = ObjectAnimator.ofFloat(holder.vBgLike, "scaleX", 0.1f, 1f);
bgScaleXAnim.setDuration(200);
bgScaleXAnim.setInterpolator(DECCELERATE_INTERPOLATOR);
ObjectAnimator bgAlphaAnim = ObjectAnimator.ofFloat(holder.vBgLike, "alpha", 1f, 0f);
bgAlphaAnim.setDuration(200);
bgAlphaAnim.setStartDelay(150);
bgAlphaAnim.setInterpolator(DECCELERATE_INTERPOLATOR);
ObjectAnimator imgScaleUpYAnim = ObjectAnimator.ofFloat(holder.ivLike, "scaleY", 0.1f, 1f);
imgScaleUpYAnim.setDuration(300);
imgScaleUpYAnim.setInterpolator(DECCELERATE_INTERPOLATOR);
ObjectAnimator imgScaleUpXAnim = ObjectAnimator.ofFloat(holder.ivLike, "scaleX", 0.1f, 1f);
imgScaleUpXAnim.setDuration(300);
imgScaleUpXAnim.setInterpolator(DECCELERATE_INTERPOLATOR);
ObjectAnimator imgScaleDownYAnim = ObjectAnimator.ofFloat(holder.ivLike, "scaleY", 1f, 0f);
imgScaleDownYAnim.setDuration(300);
imgScaleDownYAnim.setInterpolator(ACCELERATE_INTERPOLATOR);
ObjectAnimator imgScaleDownXAnim = ObjectAnimator.ofFloat(holder.ivLike, "scaleX", 1f, 0f);
imgScaleDownXAnim.setDuration(300);
imgScaleDownXAnim.setInterpolator(ACCELERATE_INTERPOLATOR);
animatorSet.playTogether(bgScaleYAnim, bgScaleXAnim, bgAlphaAnim, imgScaleUpYAnim, imgScaleUpXAnim);
animatorSet.play(imgScaleDownYAnim).with(imgScaleDownXAnim).after(imgScaleUpYAnim);
animatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
// It removes the item from the HashMap which contains this holder as key value when all animations are finisehd.
resetLikeAnimationState(holder);
}
});
animatorSet.start();
}}
在“resetLikeAnimationState”方法中。
private void resetLikeAnimationState(CellFeedViewHolder holder) {
likeAnimations.remove(holder);
holder.vBgLike.setVisibility(View.GONE);
holder.ivLike.setVisibility(View.GONE);
}
【问题讨论】:
-
简而言之 - 它可以防止此持有人视图中的动画。只需评论 if 语句,将持续时间更改为 3000 毫秒并尝试在类似视图动画的同时滚动提要。现在你懂了? :)
-
@froger_mcs -- 感谢 Miroslaw 的直接评论!不幸的是,这就是我问这个问题的原因。即使我将持续时间设置为 30000 毫秒,我仍然没有发现任何差异......这在视觉上是否像一个不明显的东西?我测试了 API21 Nexus 5 设备和 API19 Nexus 5 模拟器。如果我遗漏了什么,请再给我一个建议:-)
-
继续努力。我刚刚做了一个测试,没有 if 语句动画可以在回收处理程序中复制。下面是这个效果的一个例子:dropbox.com/s/dohm8o3nela98hj/…(心脏被旋转并停留在这个位置)。
-
@froger_mcs -- 好的!我做到了。使用编辑“animatePhotoLike”方法,没有运气。在我编辑“updateHeartButton”方法的持续时间之后。我找到了你的意思的问题。感谢您提供大量知识。我是你的忠实追随者。继续摇摆:)
标签: java android android-animation material-design objectanimator