Android Swiperefreshlayout How To Implement Canchildscrollup If Child Is Not A Listview Or Scrollview
Solution 1:
thanks to @Twibit i found a way to make this work. the trick is to detect the position of the scrollview if the position is 0 make set the SwipeRefreshLayout to be enabled else disabled.
scrollView.getViewTreeObserver().addOnScrollChangedListener(new OnScrollChangedListener() {
@Override
publicvoidonScrollChanged() {
int scrollY = scrollView.getScrollY();
if(scrollY == 0) swipeLayout.setEnabled(true);
else swipeLayout.setEnabled(false);
}
});
Solution 2:
You might have to enable / disable your swipe layout if your scroll view is or isn't on top.
You can look at this link for inspiration : https://gist.github.com/Frikish/10025057
Another example that might help you : https://developer.android.com/samples/SwipeRefreshMultipleViews/src/com.example.android.swiperefreshmultipleviews/MultiSwipeRefreshLayout.html
I had another problem with horizontal scroll : HorizontalScrollView inside SwipeRefreshLayout
Solution 3:
Extend
SwipeRefreshLayout
and overwrite the methodcanChildScrollUp()
which determines whether your views can scroll up.//if you have several scrollable views,just iteratefor (View view : ...) { if (view != null && view.isShown() && !canViewScrollUp(view)) { // If the view is shown, and can not scroll upwards, return false and start the // gesture. returnfalse; } returntrue;
Iterate through your views and use the method
canViewScrollUp()
to check if any of them can not scroll upprivatestaticbooleancanViewScrollUp(View view) { if (android.os.Build.VERSION.SDK_INT >= 14) { // For ICS and above we can call canScrollVertically() to determine this return ViewCompat.canScrollVertically(view, -1); } else { if (view instanceof AbsListView) { // Pre-ICS we need to manually check the first visible item and the child view's top // value finalAbsListViewlistView= (AbsListView) view; return listView.getChildCount() > 0 && (listView.getFirstVisiblePosition() > 0 || listView.getChildAt(0).getTop() < listView.getPaddingTop()); } else { // For all other view types we just check the getScrollY() value return view.getScrollY() > 0; } }
Post a Comment for "Android Swiperefreshlayout How To Implement Canchildscrollup If Child Is Not A Listview Or Scrollview"