Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwipeRefreshLayout with scrollView and Layout above

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?

like image 473
user3009752 Avatar asked Aug 13 '14 19:08

user3009752


People also ask

What is swipe refresh layout?

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.

What is nested scroll view?

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.

Can we use ScrollView in RelativeLayout in Android?

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….


2 Answers

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.

like image 164
jjnguy Avatar answered Sep 18 '22 23:09

jjnguy


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.

like image 20
Rishabh Avatar answered Sep 18 '22 23:09

Rishabh