Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android slide down animation

I have a toolbar aligned at the bottom and a WebView above it, which fill remaining height. Now I want to slide down the toolbar in order to hide it, and while it's animating the webview height should expand. I've tried using TranslateAnimation but unfortunetely it's not adjusting toolbar's real position, only it's contents are moved. Here's what I tried:

<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXDelta="0%"
    android:toXDelta="0%"
    android:fromYDelta="0%"
    android:toYDelta="100%"
    android:duration="700"
    android:fillAfter="true" />

And the actual code:

final View v = findViewById(R.id.browseToolbar);
Animation animation = AnimationUtils.loadAnimation(someContext, R.anim.toolbar_hide);
v.startAnimation(animation);

How can I do it?

like image 886
Sebastian Nowak Avatar asked Nov 14 '22 15:11

Sebastian Nowak


1 Answers

I wrote some code to do actual resize animations. Take a look:

http://www.touchlab.co/blog/resize-animation/

Also look at a presentation I did on Android animation

https://docs.google.com/present/view?id=djqv5kb_187c62jvbf7

Essentially, as mentioned above, the regular animation classes only affect what's in their parent view. The key to understanding them is they aren't "real". Think of the Android animation as a mirage. If you run the example app I created, say you do a scale animation and make a button smaller, if you click outside, where the button USED to be, it still registers as a button click. Android animations don't actually affect real boundaries and dimensions.

What the code in my blog post does, essentially, is implement a ViewGroup.OnHierarchyChangeListener. When stuff is added/removed from the hierarchy, the container animates a physical resize.

like image 132
Kevin Galligan Avatar answered Jan 05 '23 19:01

Kevin Galligan