Created
May 9, 2016 18:52
-
-
Save VassilisPallas/3fc3a0bce033d4ae64ad66d17e7dfccd to your computer and use it in GitHub Desktop.
custom scrollview, which disables the swipeRefreshLayout when the ScrollView isn't at the top
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context; | |
import android.util.AttributeSet; | |
import android.util.Log; | |
import android.view.MotionEvent; | |
import android.view.View; | |
import android.widget.ScrollView; | |
import android.support.v4.widget.SwipeRefreshLayout; | |
/** | |
* Created by vasilis on 12/5/15. | |
* Custom ScrollView for checking if the ScrollView is on the top or on the bottom | |
*/ | |
public class CustomScrollView extends ScrollView { | |
private SwipeRefreshLayout swipeRefreshLayout; | |
public CustomScrollView(Context context) { | |
super(context); | |
} | |
public CustomScrollView(Context context, AttributeSet attributeSet) { | |
super(context, attributeSet); | |
} | |
public void setSwipeRefreshLayout(SwipeRefreshLayout swipeRefreshLayout) { | |
this.swipeRefreshLayout = swipeRefreshLayout; | |
} | |
@Override | |
protected void onScrollChanged(int l, int t, int oldl, int oldt) { | |
View view = getChildAt(getChildCount() - 1); | |
int d = view.getBottom(); | |
d -= (getHeight() + getScrollY()); | |
if (d <= 0) { | |
// bottom | |
} else if (getScrollY() <= 0) { | |
// top | |
swipeRefreshLayout.setEnabled(true); | |
} else { | |
swipeRefreshLayout.setEnabled(false); | |
super.onScrollChanged(l, t, oldl, oldt); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment