The latest Google Newsstand App features an
ViewPager tab bar which slowly eases out the top of the screen when the list below it is scrolled down. <strong>Importantly, it eases out at the same speed the list is scrolled</strong>. When the list is scrolled upwards the
ActionBar eases back onto the screen, <strong>again at the same speed the list is scrolled</strong>.
<em>I am not referring to the
show() methods, instead I want to know how to hide and show the ActionBar at the same rate the list below it is scrolled.</em>
How is this achieved? All attempts at finding a documented solution have proven unsuccessful so any help would be appreciated.Answer1:
Create a Fragment subclass that serves as an ActionBar replacement. Use an OnScrollListener to update the fragment's view's
translationY after scroll events.
After digging around the ActionBar source code, it seems that there is no public method for accessing the ActionBar container view. But where there's a will, <a href="https://stackoverflow.com/questions/20023483/how-to-get-actionbar-view" rel="nofollow">there's a way</a>.
You can grab a reference to the Action Bar's view using the following:
int resId = getResources().getIdentifier("action_bar_container", "id", "android"); View actionBarContainer = findViewById(resId);
action_bar_container is a private ID, so it's subject to Google's whims. Use at your own risk.
Once you have the Action Bar's view, you can animate it however you'd like.
I hacked together <a href="https://github.com/bamatson/PushPullActionBarDemo" rel="nofollow">a semi-functional example</a> if you're interested.
Hope this helps!