1

I working with SwipeRefreshLayout. Here what my need is... Im using one Linearlayout inside SwipeRefreshLayout which is in "RED COLOR". when im trying to pull down that layout, that layout is not moving. Only its showing that refresh circular arrow, But i want to pull down that whole "Red color" layout. How to achieve this?

Please find my sources for reference.

Suggestion please....

mylayout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000">


<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/swipeRefreshLayout_emptyView"
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:background="#ff0000"
    >

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"

            android:gravity="center"
            >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Sample SwipeRefreshLayout"
                android:layout_marginTop="50dp"
                android:textColor="#ffffff" />

        </LinearLayout>
    </ScrollView>

</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>

MyClass.java

public class MyClass extends Fragment implements SwipeRefreshLayout.OnRefreshListener {

private SwipeRefreshLayout swipeLayout;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.mylayout,null);


    swipeLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipeRefreshLayout_emptyView);
    onCreateSwipeToRefresh(swipeLayout);


    return  view;
}

private void onCreateSwipeToRefresh(SwipeRefreshLayout swipeLayout) {

    swipeLayout.setOnRefreshListener(this);
    swipeLayout.setColorSchemeColors(android.R.color.holo_green_dark,  android.R.color.holo_red_dark,
            android.R.color.holo_blue_dark,   android.R.color.holo_orange_dark);

}


@Override
public void onRefresh() {

    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
}
prabu
  • 717
  • 3
  • 12
  • 30

3 Answers3

0

Instead for using a ScrollView as child of SwipeRefreshLayout, try using a RelativeLayout / LinearLayout and make the ScrollView a child of it.

something like this:

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/swipeRefreshLayout_emptyView"
    android:layout_width="match_parent"
    android:layout_height="300dp"
    >
   <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ff0000">
       <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            
            //Leave the interior the same

       </ScrollView>
   </LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>

Also apply the red color to your LinearLayout. You currently have it in your SwipeRefreshLayout

Boken
  • 4,825
  • 10
  • 32
  • 42
Victor Gomes
  • 128
  • 10
  • but still that red color whole layout is not moving :( – prabu Jun 22 '16 at 10:30
  • any other solutions or ideas? – prabu Jun 22 '16 at 10:42
  • Please note that i've edited my answer. I removed the background definition from the SwipeRefreshLayout, and added it into the LinearLayout., it worked for me. Please also check this answer - > http://stackoverflow.com/questions/25294395/swiperefreshlayout-with-scrollview-and-layout-above?rq=1 (I belive your ScrollView might be the problem) – Victor Gomes Jun 22 '16 at 10:48
0

Your ScrollView should not wrap_content on its height but match_parent

Xavier Falempin
  • 1,186
  • 7
  • 19
  • i've followed your suggestion..but still can't able to move that layout. any other solutions or ideas? – prabu Jun 22 '16 at 10:46
0

Used PullRefreshLayout instead SwipeRefreshLayout from this sample

Boken
  • 4,825
  • 10
  • 32
  • 42
prabu
  • 717
  • 3
  • 12
  • 30