1

Imagine having a panel, say an stickers panel (something like Viber or Telegram) in your app which needs to be visible and gone every now and then.

What would be the proper way of showing/hiding it? For example I used to change (animate) the height of the wrapper layout but it wasn't very performance friendly.

Should I just change the visibility and be done? Or a better way can be utilized? (Preferably an animated approach would be nice.)

2hamed
  • 8,719
  • 13
  • 69
  • 112
  • This depends entirely on you. You can set visibility to Gone and be ok with it. Maybe you think it is ugly, so you add alpha animation to let it disappear or translate animation to meve it off the screen. Entirely up to you... – slezadav May 26 '15 at 11:12

2 Answers2

3

Use view.setTranslationY(translationAmount), and animate with view.animate().translationY(-translationAmount).start().

translationAmount could be the height of the view, changing the sign of this measurement will invert the direction of motion.

A translation animation is much more efficient than changing the view height or other layout parameters because you don't have to traverse the view tree and re-draw everything.

memoizr
  • 2,081
  • 2
  • 18
  • 24
  • I think I'll go with translation, I just need to figure out how make it as big as soft keyboard. – 2hamed May 26 '15 at 11:42
  • For that you can have a look at this other question: http://stackoverflow.com/questions/16788959/is-there-any-way-in-android-to-get-the-height-of-virtual-keyboard-of-device – memoizr May 26 '15 at 11:44
  • Yeah I was checking it out. ;) – 2hamed May 26 '15 at 11:46
2

you can apply animation to the view like view.animate().translationY(distance);

applying view.setVisibility(View.VISIBLE); and view.setVisibility(View.GONE);is required to display and hide the view.

you will have a proper idea by referring this.

Community
  • 1
  • 1