Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RecyclerView drawing offscreen, can't scroll bottom item into view

Using Design Support Library 22.2.1, with the following View hierarchy:

<DrawerLayout
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:fitsSystemWindows="true">
    <CoordinatorLayout
     android:layout_width="match_parent"
     android:layout_height="match_parent">
        <AppBarLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content">
            <Toolbar
             android:layout_width="match_parent"
             android:layout_height="?attr/actionBarSize" />
            <TabLayout
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:clipToPadding="false"
             app:tabGravity="fill"
             app:tabMode="scrollable" />
        </AppBarLayout>
        <FrameLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior">

            <!-- Fragments replaced here -->
            <LinearLayout
             android:orientation="vertical"
             android:layout_width="match_parent"
             android:layout_height="match_parent">
                <CustomDashboardView
                 android:layout_width="match_parent"
                 android:layout_height="120dp" />
                <ViewPager
                 android:layout_width="match_parent"
                 android:layout_height="match_parent">

                    <!-- Tab Fragments go here -->
                    <LinearLayout
                     android:orientation="vertical"
                     android:layout_width="match_parent"
                     android:layout_height="match_parent">
                        <CustomEmptyErrorLayout
                         android:layout_width="match_parent"
                         android:layout_height="match_parent"
                         android:visibility="gone" />
                        <android.support.v7.widget.RecyclerView
                         android:layout_width="match_parent"
                         android:layout_height="match_parent" />
                    </LinearLayout>

                </ViewPager>
            </LinearLayout>

        </FrameLayout>
    </CoordinatorLayout>
    <NavigationView
     android:layout_height="match_parent"
     android:layout_width="wrap_content"
     android:fitsSystemWindows="true" />
</DrawerLayout>

I run into this problem where the RecyclerView's height is larger than the visible area in which it should be contained, so it looks like the RecyclerView is drawing offscreen, and it is impossible to scroll the last item in the RecyclerView into full view. There is also no movement regarding the Toolbar nor TabLayout (although a layout_behaviour is applied to the FrameLayout).

annotated screenshot highlighting the issue

I had reported this as a bug, but ol' Banesy has stated this is working as intended. If that is the case, how can I avoid this intended behviour in favour of a RecyclerView that respects layout_height="match_parent" and draws its items within the visible screen? https://code.google.com/p/android/issues/detail?id=182391

UPDATE: now with Design Support v23, it's not looking good at all. I've narrowed this down to the Design Support lib itself (i.e. updating RecyclerView, appcompat, whatever else to v23 while leaving Design Support v22.2.1 yields the same problem as described above). So the new look, the CustomDashboardLayout and RecyclerView have gone AWOL, hopefully this isn't working as intended either:

enter image description here

like image 337
straya Avatar asked Aug 13 '15 01:08

straya


1 Answers

I've managed to fix this on v23 and found a workaround for v22.2.1. The fact between the versions the behaviour is quite different leads me to believe "working as intended" isn't the whole truth.

v23 fix: CustomDashboardLayout above the ViewPager was causing the problem, when it wasn't forced to visibility="gone" the ViewPager wasn't being added to hierarchy at all. With it gone, the ViewPager is added and the RecyclerView sizes its height correctly.

v22.2.1 workaround: the v23 fix has no affect on v22.2.1, the workaround is to set layout_marginBottom="?attr/actionBarSize" on the RecyclerView.

Glad that's over anyway.

like image 130
straya Avatar answered Oct 30 '22 09:10

straya