如何为API 21/Lollipop以下的设备实现setZ()?

Gen*_*337 6 android

我已经成功实现了一个拖动幻灯片动画,其setZ()功能如下:

dragAnimSet.setAnimationListener(new Animation.AnimationListener() {
    @Override
    public void onAnimationStart(Animation animation) {
        ((ViewGroup)sourceParent.getParent()).setClipChildren(false);
        for(int a = 0; a < ifvList.size(); a++)
        {
            if(a != sourceIndex && a != indexInListener)
            {
                ifvList.get(a).setZ(-20);
            }
        }
        if(sourceParent.indexOfChild(toReplace) != -1 && toReplaceParent.indexOfChild(source) != -1) {
            source.setZ(-10);
        } else {
            sourceParent.setZ(-10);
        }
    }

    @Override
    public void onAnimationEnd(Animation animation) {
        ((ViewGroup)sourceParent.getParent()).setClipChildren(true);
        for(int a = 0; a < ifvList.size(); a++)
            {
                if(a != sourceIndex && a != indexInListener)
                {
                    ifvList.get(a).setZ(0);
                }
            }
            source.setZ(0);
            sourceParent.setZ(0);
        }

    @Override
    public void onAnimationRepeat(Animation animation) {}
});
Run Code Online (Sandbox Code Playgroud)

但是,应用程序我在目标设备中使用它,最小API为15,该功能setZ()仅适用于API 21及更高版本.

bringToFront() 或者更改绘制顺序将不起作用,因为它是一个LinearLayout,而前者只是将视图带到列表的末尾.

我怎样才能至少模仿setZ()API 21以下设备的效果?

ian*_*ake 1

Lollipop 之前没有立面图,因此没有setZ():绘制顺序始终按照添加视图的顺序。

ViewCompat.setZ(),但显然它在 Lollipop 之前没有做任何事情,只是允许您删除任何版本检查。