请查看此页面-> http://frogermcs.github.io/InstaMaterial-concept-part-5-like_action_effects/
我只是在学习 InstaMaterial 的源代码。我几乎理解了大部分代码。但我不明白 FeedAdapter 中的 "likeAnimations" 变量代表什么。
我知道这是一个 HashMap 。我以为这是为了防止重复调用。但事实并非如此...
谁能解释一下这个变量的用途吗?
FeedAdapter 的完整源代码在这里 -> https://github.com/frogermcs/InstaMaterial/blob/master/app/src/main/java/io/github/froger/instamaterial/ui/adapter/FeedAdapter.java
我将感谢任何进展。
在成员(member)字段。
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);
}
最佳答案
谢谢,米罗斯瓦夫!
(正如 miroslaw 在我的问题下评论的那样)
关于java - 我想从 InstaMaterial(Miroslaw Stanek)了解这个变量的用途,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29364657/