From 73e42558e3083fe1f4fc2a1ac4f168d5297895a7 Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 18 Dec 2014 14:26:09 +0200 Subject: [PATCH] Floating button will now dissapaer when scroll down and appear when scroll up --- OsmAnd/res/layout/dashboard.xml | 1 + .../plus/activities/MainMenuActivity.java | 35 ++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) 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; + } + + }); } }