I have faced with one problem while implementing ScrollView in my application. I am using great library Android-ObservableScrollView.
My goal is to hide toolbar when user slides down the view and than bring it back when user scrolls up.
I have extended ToolbarControlBaseActivity but the implementation of this abstract class is pretty the same as in the example.
There is callback for handling scrolling and canceling events.
@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
//TODO: this method is not being called
Log.e("DEBUG", "onUpOrCancelMotionEvent: " + scrollState);
if (scrollState == ScrollState.UP) {
if (toolbarIsShown()) {
Log.d("SCROLL", "Hide toolbar");
hideToolbar();
scrollUpEvent();
}
} else if (scrollState == ScrollState.DOWN) {
if (toolbarIsHidden()) {
Log.d("SCROLL", "Show toolbar");
showToolbar();
scrollDownEvent();
}
}
}
This callback is never called.
Internally it is implemented in the following way
if (mCallbacks != null) {
switch (ev.getActionMasked()) {
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
mIntercepted = false;
mDragging = false;
mCallbacks.onUpOrCancelMotionEvent(mScrollState);
break;
Of course I set listener
mScrollable.setScrollViewCallbacks(this);
But it doesn't work.
My layout file has the next content
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:app="http://ift.tt/GEGVYd"
xmlns:tools="http://ift.tt/LrGmb4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/base_bg_color"
tools:context=".MalibuMainPageActivity">
<com.github.ksoichiro.android.observablescrollview.ObservableScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:text="@string/hello_world"
android:paddingTop="?attr/actionBarSize"
>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="@dimen/banner_height"
android:orientation="vertical">
<ViewPager
android:id="@+id/banner_slider"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.viewpagerindicator.CirclePageIndicator
android:id="@+id/slide_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:padding="10dip"
app:fillColor="@color/colorPrimary" />
</FrameLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello"
android:textSize="20sp" />
<TextView
android:id="@+id/body"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:background="@android:color/white"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:layout_margin="20dp"
android:text="@string/lipsum" />
</LinearLayout>
</com.github.ksoichiro.android.observablescrollview.ObservableScrollView>
<include layout="@layout/toolbar"/>
</FrameLayout>
I haven't debug library internally yet, maybe someone already has the same problem or knows what can cause such behavior.
As temporary solution I am using another callback.
@Override
public void onScrollChanged(int yPosition, boolean firstScroll, boolean b1) {
if((yPosition<=mToolBarSize) && (yPosition!= mPreviousYPos)) {
this.mBannerSlider.startAutoScroll();
Log.d("SCROLL", "Scrolled up, enable autoslide");
if(!super.toolbarIsShown()) {
super.showToolbar();
}
}
else if(firstScroll && yPosition>mToolBarSize) {
Log.d("SCROLL", "First scroll down disable autoslide");
this.mBannerSlider.stopAutoScroll();
if(super.toolbarIsShown()) {
super.hideToolbar();
}
}
mPreviousYPos = yPosition;
}
But it seems to work a bit laggy when ToolBar appears
Aucun commentaire:
Enregistrer un commentaire