我已成功使用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) {}
});
然而,我在使用的应用程序面向最低API为15的设备,而函数setZ()
仅适用于API 21及以上版本。
bringToFront()
或更改绘制顺序不起作用,因为它是一个LinearLayout,前者只会将视图移到列表的末尾。
对于API 21以下的设备,如何至少模拟setZ()
的效果?
ViewCompat.setZ(<view_to_elevate>,<new_z_value>)
? - Gensoukyou1337setZ()
一样。 - ianhanniballakeViewCompat.setTranslationZ()
做的事情和setZ()
一样吗?因为当我查看我的版本的 ViewCompat 时,发现setZ()
不存在。 - Gensoukyou1337view.setZ()
和view.setTranslationZ()
有着不同的功能一样,这两个也是如此。你应该尽快升级到最新的支持库(目前是24.0.0版本)。 - ianhanniballake