Ok, so i`m trying to get the scrollY atribute from my RecycleView (to see the position of where i am scrolling in the CardList. I have the following setup
First, the main activity , which houses a SlidingTabs layout, which has a SwipeToFresh layout as he child and a ViewPager for the 2 fragments of the tabs, like this :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.popal.soul.MovieListActivity">
<com.example.popal.soul.SlidingTabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="2dp"
android:background="@color/ColorPrimary"/>
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="1">
</android.support.v4.view.ViewPager>
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
Then i have each fragment with an identical layout, like this, with an RecycleView :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v7.widget.RecyclerView
android:id="@+id/cardList"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
And finally the layout for each card of the RecycleView (i don't think it matters, but i'll add it anyway)
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
card_view:cardCornerRadius="4dp"
android:layout_margin="5dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/selectableItemBackground">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="20dp"
android:background="@color/bkg_card"
android:text="Movie Title"
android:gravity="center_vertical"
android:textColor="@android:color/white"
android:textSize="14dp"/>
<ImageView
android:elevation="5dp"
android:scaleType="fitCenter"
android:layout_width="100dp"
android:layout_height="150dp"
android:id="@+id/imageViewPoster"
android:text="Poster"
android:gravity="center_vertical"
android:layout_below="@id/title"
android:layout_marginTop="10dp"
android:layout_marginLeft="5dp"/>
<ImageView
android:id="@+id/imageViewFanart"
android:scaleType="fitCenter"
android:layout_alignBottom="@+id/imageViewPoster"
android:layout_toEndOf="@+id/imageViewPoster"
android:layout_width= "235dp"
android:layout_height="122dp"
android:layout_marginRight="5dp"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
Now, i am trying to get the scrolling position of the RecycleView items from the main activity, where the SwipeToRefresh layout is defined. I need to do this to implement this workaround regarding a bug in the SwipeToRefresh layout, where trying to scroll up from the bottom of the list will trigger the refresh call : SwipeRefreshLayout + WebView when scroll position is at top , but as you can see, both solutions require access to the Swipe Container and RecycleView, in the same class or activity.
I tried using something like int scrollY = pager.getChildAt(pager.getCurrentItem()).getScrollY();
Which should theoretically return the position of the child item (in this case, the RecycleView) , but it still returns 0 (added log entries to get real-time events when the scrolling state has change), like if was still returning the position of the ViewPage adapter.
Anybody have an ideea?