I am trying to apply SwipeRefrshLayout on my tabbed view.
This is layout file of tab fragment in which i want swipeRefreshLayout
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:divider="@null" />
</ScrollView>
This is layout file of of activity
<RelativeLayout 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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/action_bar"
style="@style/Widget.MaterialSheetFab.ToolBar" />
<com.astuetz.PagerSlidingTabStrip
android:id="@+id/tabs"
style="@style/Widget.MaterialSheetFab.TabLayout" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swiperefresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_below="@+id/appbar"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
</RelativeLayout>
Code in fragment file:
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (SuperAwesomeCardFragment.listAchievements.getChildAt(0) != null) {
StudentInfoMainActivity.swipeRefreshLayout.setEnabled(listAchievements.getFirstVisiblePosition() == 0 && listAchievements.getChildAt(0).getTop() == 0);
}
}
after applying the above layout and code sample shown in the sample codes by google, i was successfully able to implement the swiperefreshllayout. But there was a problem of not able to scroll down, as swipe was overriding it. As per the thread on stack overflow https://stackoverflow.com/a/35779571/4180170, i added the code that solved my problem. But it added one more problem. A scenario where the first row of the list is bigger in height then my screen size, then the list shows only the first element. Other elements are not shown on the screen. This happens only when first element in the row is bigger. If i add another one row with height less than or equal to screen size, then all elements are being shown properly.
Other point that i would like to highlight is that if i use similar code in activity (Instead of Tabs or Fragments) than it works perfectly as expected and the following problem is not encountered. This is some kind of weird.
I have added two images: Image1: In this image, the first element in the list view have height less than the screen height, so all the element in the listView are visible on scrolling up and down.
Image2: Here i have just deleted the first element of list view from image 1. so the photo seen is the first element now in the listview. In this case as seen in the image, the height of the element(Image+padding and all) is greater than the screen size (height). Now when i try to scroll down, scroll is going only till the image is seen full. On Scrolling down, i am not able to see any of the other rows in the listview.
Update: Getting following line in Logcat multiple times
10-30 08:56:02.851 19665-19665/com.malav.holistree E/SwipeRefreshLayout: Got ACTION_MOVE event but don't have an active pointer id.