We have app:layout_behavior="@string/appbar_scrolling_view_behavior"; It's work perfect for toolbar. I create custom BottomBar and wanna invert the direction of moving which causes this flag. Is there any ideas how to implement it?
Asked
Active
Viewed 567 times
-1
-
your question is quite unclear.... – PN10 Sep 30 '16 at 11:20
-
I want to extend the functionality's behavior of this flag and invert the direction of moving by axis y. For example we have recyclerview, scrolling down, toolbar hide to top, bottom bar to bot, scroll up, all shown again – Eduard Poida Sep 30 '16 at 11:30
-
check answer from Mario from this .http://stackoverflow.com/questions/32465548/add-app-bar-scrolling-view-behavior-to-multiple-views-in-coordinatorlayout .from what i understood from your comment is you need app scrolling behavior for multiple views...isn't it?? and one more thing check how to form and ask question on SO you should explain your problem statement clearly...your title and body should be more clear... – PN10 Sep 30 '16 at 11:54
2 Answers
0
I found solution!
We need to extend CoordinatorLayout.Behavior like this
public class BottomBarBehavior<V extends View> extends CoordinatorLayout.Behavior<V> {
private int defaultDependencyTop = -1;
public BottomBarBehavior(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean layoutDependsOn(CoordinatorLayout parent, V child, View dependency) {
return dependency instanceof AppBarLayout;
}
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, V child, View dependency) {
if (defaultDependencyTop == -1) {
defaultDependencyTop = dependency.getTop();
}
child.setTranslationY(-dependency.getTop() + defaultDependencyTop);
return true;
}
}

Eduard Poida
- 23
- 3
0
Eduard Poida your solution doesn't work properly when one changes the orientation of the phone while the Bottom Navigation is hidden.Screenshot
I have modified one line of your solution and it works better for me:
public class BottomNavigationBehavior<V extends View> extends CoordinatorLayout.Behavior<V>
{
private int defaultDependencyTop = -1;
public BottomNavigationBehavior(Context context, AttributeSet attrs)
{
super(context, attrs);
}
@Override
public boolean layoutDependsOn(CoordinatorLayout parent, V child, View dependency)
{
return dependency instanceof AppBarLayout;
}
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, V child, View dependency)
{
if (defaultDependencyTop == -1)
{
defaultDependencyTop = dependency.getTop();
}
child.setTranslationY(-dependency.getTop()*2);
return true;
}
}

Celt K. B.
- 779
- 6
- 18
-
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. If you [earn](//meta.stackoverflow.com/q/146472) sufficient [reputation](//stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](//stackoverflow.com/help/privileges/comment). – Machavity Aug 02 '17 at 14:47