java - 在动画期间更改 Z 顺序

标签 java android animation view z-order

我有 2 个具有相同动画的 View ,在此动画期间,这些 View 应更改您的 Z 顺序,例如,在动画期间, View A 在 View B 上方我更改此顺序,我通过 viewA 或 viewB 获取此顺序。带到前面();但是更新不是立即进行的,我需要在确切的时间点更改此 Z 顺序。

谢谢。

最佳答案

我是这样解决的:

首先在动画中设置自定义插值器,您的类需要实现 ICustomInterpolator

animation.setInterpolator(new CustomInterpolator(this));
a.startAnimation(animation);
b.startAnimation(animation);

之后

public void currentProgress(float p, float time) {
    if(time == yourTime){
        a.bringToFront();
        a.invalidate();
        b.invalidate();
        a.requestLayout();
        b.requestLayout();
    }
}

currentProgress 是自定义插值器的接口(interface)方法:

public interface ICustomInterpolator {
    public void currentProgress(float p, float time);
}

在自定义插值器中:

public class CustomInterpolator extends
    AccelerateDecelerateInterpolator {

    private ICustomInterpolator delegate;

    public <T extends ICustomInterpolator> CustomInterpolator(T delegate) {
        super();
        this.delegate = delegate;
    }

    @Override
    public float getInterpolation(float input) {
        delegate.currentProgress(input);
        return super.getInterpolation(input);
    }
}

关于java - 在动画期间更改 Z 顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11938496/

相关文章:

jquery - 如何在单击按钮时向上/向下滑动隐藏的 div?

javascript - 如何删除 HTML 5 Canvas 中的形状?

java - 如何使用嵌套的 if 语句而不是 System.exit(0); 来阻止程序在蓝图类中运行?

android - 适配器错误中的 TextView.setText()

Android Room Composite 主键问题

android - Dagger - android.app.IntentService 与 @Inject

javascript - 使用 eCharts 重复动画

java - Xuggler 从 rtsp 流中获取 jpeg 图像

java - 接口(interface)中的 protected 方法

java - 检查指定时间内的变量变化?