The translated view (AppBarLayout) is returned to its original position

I'm on API 22. Orange view AppBarLayout

inside CoordinatorLayout

. I am trying to make it disappear by moving it to the top. I want him to come out of the screen.

I get the translation height:

AppBarLayout bar;
Rect r = new Rect();
bar.getLocalVisibleRect(r );
float h = r.height();

      

  • Animated is just a challenge bar.animate().translationY(-h)

    , etc .; (tried also ViewCompat.animate (bar), new TranslateAnimation (), ...)
  • A direct call is a direct call bar.setTranslationY(-h)

    .

enter image description here

The problem is that it is instantly replaced in its original location and the translation goes back to 0 (i.e. bar.getTranslationY() == 0

, even if I just set it to -h

). I spent several hours on this; you might think

It may not be possible; Layout Coordinator does not allow this behavior

This is not true. The same code works like an API17 charm, and in the last hours I haven't figured out why it shouldn't be on API22. I would appreciate any help in understanding why this is not possible, or what is the difference between API17 and API22 that calls this.

Or maybe how to fix the problem. Sorry for the low frame rate. (Side question: Should I file a bug report? Do you think this is a bug?)

+3


source to share





All Articles