I have the following layout
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > //some views here </LinearLayout> <ScrollView android:layout_width="match_parent" android:layout_height="wrap_content" > <TableLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:stretchColumns="*" > </TableLayout> </LinearLayout> </android.support.v4.widget.SwipeRefreshLayout>
The problem is when I scrolldown the table, I can't scrollUp again because the swipelayout is being triggered. How can I trigger the swiperefresh only when the first view of the table is visible?
Android SwipeRefreshLayout is a ViewGroup that can hold only one scrollable child. It can be either a ScrollView, ListView or RecyclerView. The basic need for a SwipeRefreshLayout is to allow the users to refresh the screen manually. This is pretty common in the Facebook Newsfeed screen.
NestedScrollView is just like ScrollView , but it supports acting as both a nested scrolling parent and child on both new and old versions of Android. Nested scrolling is enabled by default.
ScrollView is a ViewGroup that make the view hierarchy placed within it scrollable. You may only need to place one other ViewGroup inside it as a child. To add many Views to ScrollView, just directly add them to the child ViewGroup such as: RelativeLayout, LinearLayout….
I found that if you replace your ScrollView
with a android.support.v4.widget.NestedScrollView
the scrolling behavior will work as you expect it to.
Make your own implementation of SwipeRefreshLayout and override the canChildScrollUp in this way:
@Override public boolean canChildScrollUp() { if (scrollView != null) return scrollView.canScrollVertically(-1); return false; }
just replace with any subclass of ScrollView.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With