I've succeeded in implementing a drag-slide animation with the setZ()
function as follows:
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) {}
});
However, the app I'm using this in targets devices with a minimum API of 15, and the function setZ()
only works for API 21 and above.
bringToFront()
or changing the draw order won't work because it's a LinearLayout and the former will just bring the view to the end of the list.
How can I at least emulate the effect of setZ()
for devices below API 21?
There is no elevation prior to Lollipop, hence no setZ()
: the order of drawing is always in order of the views being added.
There is ViewCompat.setZ(), but obviously it doesn't do anything prior to Lollipop, just allows you to remove any version checks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With