Translated view (AppBarLayout) is put back in its original position

757 Views Asked by At

I'm on API 22. The orange view is an AppBarLayout inside a CoordinatorLayout. I'm trying to make it disappear by translating it to the top. I want it to get out of the screen.

I'm getting translation height from:

AppBarLayout bar;
Rect r = new Rect();
bar.getLocalVisibleRect(r );
float h = r.height();
  • Animated is just a call to bar.animate().translationY(-h) and so on; (tried also ViewCompat.animate(bar), new TranslateAnimation(), ...)
  • Direct call is a direct call to bar.setTranslationY(-h).

enter image description here

Problem is that it gets instantly replaced at its previous place, and translation gets back to 0 (i.e., bar.getTranslationY() == 0, even if I have just set it to -h). I spent hours on this; you might think

Maybe it's not possible; CoordinatorLayout is not allowing such behavior

That's not true. The exact same code works like a charm on API17, and in last hours I failed to see why it should not on API22. I would appreciate any help, either in understanding why this is not possible, or what's the difference between API17 & API22 that causes this.

Or, maybe, how to get around the problem. Sorry for the low framerate. (Side question: should I file a bug report? do you believe it's a bug?)

0

There are 0 best solutions below