diff --git a/OsmAnd/res/layout/dashboard.xml b/OsmAnd/res/layout/dashboard.xml index 6a36d915b4..41c50ed252 100644 --- a/OsmAnd/res/layout/dashboard.xml +++ b/OsmAnd/res/layout/dashboard.xml @@ -2,6 +2,7 @@ = Build.VERSION_CODES.ICE_CREAM_SANDWICH) { - FloatingActionButton fabButton = new FloatingActionButton.Builder(this) + final FloatingActionButton fabButton = new FloatingActionButton.Builder(this) .withDrawable(getResources().getDrawable(R.drawable.ic_action_map)) .withButtonColor(Color.parseColor("#ff8f00")) .withGravity(Gravity.BOTTOM | Gravity.RIGHT) @@ -125,6 +127,37 @@ public class MainMenuActivity extends BaseDownloadActivity implements OsmAndLoca startMapActivity(); } }); + + final ScrollView mainScroll = (ScrollView) findViewById(R.id.main_scroll); + if (mainScroll == null){ + return; + } + mainScroll.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() { + private int previousScroll = 0; + + @Override + public void onScrollChanged() { + int scrollY = mainScroll.getScrollY(); + if (previousScroll == scrollY){ + return; + } + + if (scrollY > previousScroll && previousScroll >= 0){ + if (!fabButton.isHidden() ){ + fabButton.hideFloatingActionButton(); + } + } else { + int layoutHeight = mainScroll.getChildAt(0).getMeasuredHeight(); + int scrollHeight = scrollY + mainScroll.getHeight(); + //scroll can actually be more than entire layout height + if (fabButton.isHidden() && scrollHeight < layoutHeight){ + fabButton.showFloatingActionButton(); + } + } + previousScroll = scrollY; + } + + }); } }