Search code examples
androidandroid-fragmentsscrollandroid-viewpagerandroid-recyclerview

why wont my recycler view scroll?


screen

been scowering the internet on this seems to happen a lot for a lot of reasons but I can't solve mine the two recycler views go into the view pagers but will not scroll, ive tried nested scroll views on the view pager and on the fragment holding the recycler view, tried just using the scroll behaviour tags on linear layouts, but no joy I tried changing the layout manager to horizontal and while it doesn't scroll it does give me the animation of a scroll view at the end of its layout, I'm using a grid layout, I've also heard it can come from using the app bar layout can someone offer some advice

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />
<RelativeLayout
    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:id="@+id/wherethecardsgo">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1">

        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/border"
            android:layout_margin="10dp"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
             />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/fab_margin"
        android:src="@drawable/ic_playlist_play_white_24dp"
        android:layout_alignBottom="@id/viewpager2"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    </RelativeLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1">

<android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabMode="scrollable"
        app:tabGravity="fill"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />


<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:background="@color/windowBackground"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:layout_below="@+id/tabs" />

</RelativeLayout>
    </LinearLayout>
</RelativeLayout>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />


<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    android:src="@drawable/plus" />

</android.support.design.widget.CoordinatorLayout>

and this is one of the recycler views

<RelativeLayout 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"
tools:context=".TwoFragment">


    <android.support.v7.widget.RecyclerView
        android:id="@+id/card_grid"
        android:scrollbars="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</RelativeLayout>

Solution

  • SOLVED

    It was an issue of the appbar stealing focus so i pushed the appbar to the bottom of my layout and suddenly my recycler views are now scrolling! My xml now looks like this

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout  
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity">
    
    
    
    <RelativeLayout
        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:background="@color/colorPrimary"
        android:id="@+id/wherethecardsgo">
    
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1">
    
            <android.support.v4.view.ViewPager
                android:id="@+id/viewpager2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/border"
                android:layout_marginLeft="10dp"
                android:layout_marginBottom="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="64dp"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                 />
    
        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/fab_margin"
            android:src="@drawable/ic_playlist_play_white_24dp"
            android:layout_alignBottom="@id/viewpager2"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true" />
    
        </RelativeLayout>
    
    
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1">
    
    <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
            app:tabMode="scrollable"
            app:tabGravity="fill"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
    
    
    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:background="@color/windowBackground"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:layout_below="@+id/tabs" />
    
    </RelativeLayout>
        </LinearLayout>
    </RelativeLayout>
    
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">
    
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />
    
    </android.support.design.widget.AppBarLayout>
    
    <include layout="@layout/content_main" />
    
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:src="@drawable/plus" />
    
    </android.support.design.widget.CoordinatorLayout>