gpt4 book ai didi

java - Android CircularReveal 错误 : Not working after starting another type of animator on the same view

转载 作者:行者123 更新时间:2023-11-30 05:02:20 25 4
gpt4 key购买 nike

我有一个带有 RecyclerView 的应用程序,在每个项目中,我都使用 onTouch() 实现了滑动以加注星标/关闭行为。我的实现没有问题,我可以处理左右滑动并从 RecyclerView 声明拖动。

每一项都是RevealFrameLayout,上面是content,下面是原始布局和要显示的布局,就像这样:

顶部布局:

Top layout:

下方布局(顶部显示层):

Below layout (top revealed layer):

下方布局(显示前的默认布局):

Below layout (default layout before reveal):

在那里我揭示了顶部显示层(彩色层)并且一切正常,直到我添加了另一个 ObjectAnimator 来隐藏星形布局(使星形/非星形),当显示第一次工作时,然后将执行另一次滑动隐藏动画师,然后第 3 次,它应该再次显示的地方,它真正启动了动画(通过调试 start() 被执行)但它没有显示。第 4 次隐藏动画师工作但没有显示布局。

Behavior gif:

触发任何 Action 的方法:

void triggerAction(SwipeAction swipeAction, final Note note, final int position) {
if (swipeAction.getActionId() == SwipeAction.STAR) {
if (note.isStarred() && !hidden && !hideAnimating && !justAnimated) {
starActionLayout.setVisibility(View.VISIBLE);
archiveActionLayout.setVisibility(View.GONE);
Animator hideAnim = AnimationUtils.createHideAnimation(revealStar);
hideAnim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
revealStar.setVisibility(View.INVISIBLE);
hideAnimating = false;
hidden = true;
note.setStarred(false);
MainActivity.notesController.set(position, note);
super.onAnimationEnd(animation);
}
});
hideAnim.start();
revealStar.setVisibility(View.VISIBLE); // DEBUG: Only to make sure the star layout is shown.
justAnimated = true;
hideAnimating = true;
revealAnimating = false;
revealed = false;
hidden = false;
} else if (!note.isStarred() && !revealAnimating && !revealed && !justAnimated) {
starActionLayout.setVisibility(View.VISIBLE);
archiveActionLayout.setVisibility(View.GONE);
final ObjectAnimator revealAnim = (ObjectAnimator) AnimationUtils.createCircularReveal(revealStar, (int) getCenterX(starActionImage), (int) getCenterY(starActionImage), 0, (float) getRadius(starActionLayout));
revealAnim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
revealAnimating = false;
revealed = true;
note.setStarred(true);
MainActivity.notesController.set(position, note);
super.onAnimationEnd(animation);
}
});
revealAnim.start();
justAnimated = true;
revealAnimating = true;
hideAnimating = false;
hidden = false;
revealed = false;
revealStar.setVisibility(View.VISIBLE);
}
} else if (swipeAction.getActionId() == SwipeAction.ARCHIVE) {
if (!revealAnimating && !revealed) {
int added = starActionLayout.getWidth();
starActionLayout.setVisibility(View.GONE);
archiveActionLayout.setVisibility(View.VISIBLE);
Animator revealAnim = AnimationUtils.createCircularReveal(revealArchive, (int) getCenterX(archiveActionImage) + added, (int) getCenterY(archiveActionImage), 0, (float) getRadius(archiveActionLayout));
revealAnim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
revealAnimating = false;
revealed = true;
super.onAnimationEnd(animation);
}
});
revealAnim.start();
revealAnimating = true;
revealArchive.setVisibility(View.VISIBLE);
}
}
}

我的条件没有问题,因为调试显示 reveal animator show 代码在应该执行的时候执行。 AnimationUtils 是一个自定义类,它包装了 ViewAnimationUtils.createCircularReveal(params) 和另一个自定义 ObjectAnimator createHideAnimator() 并且也没有问题。

AnimationUtils.java:

package com.skaldebane.util.graphics;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.os.Build;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.animation.LinearInterpolator;

public class AnimationUtils {

public static Animator createCircularReveal(View view, int centerX, int centerY, float startRadius, float endRadius) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) return ViewAnimationUtils.createCircularReveal(view, centerX, centerY, startRadius, endRadius);
else return io.codetail.animation.ViewAnimationUtils.createCircularReveal(view, centerX, centerY, startRadius, endRadius);
}

public static Animator createHideAnimation(View view) {
ObjectAnimator hideAnim = new ObjectAnimator();
hideAnim.setPropertyName("alpha");
hideAnim.setFloatValues(1.0F, 0.0F);
hideAnim.setDuration(300);
hideAnim.setInterpolator(new LinearInterpolator());
hideAnim.setTarget(view);
return hideAnim;
}

}

注意:不要告诉我改用 ItemTouchHelper,因为这不是我的问题的主题,也不能解决问题。

最佳答案

我刚刚发现了问题。这很简单,但很难注意到。当我应用隐藏动画器时,它会将 alpha 永久设置为 0,这意味着该 View 将永远不会再次出现。我只需要在调用 view.setVisiblity(View.INVISIBLE); 之后直接使用 view.setAlpha(1.0F);

关于java - Android CircularReveal 错误 : Not working after starting another type of animator on the same view,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58047197/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com