Moritz
Moritz

Reputation: 21

recyclerview items outside view bound invisible

I have the following situation: I have a vertical RecyclerView with padding and the parent layouts clipChildren and clipToPadding set to false like so:

<LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:clipChildren="false"
                android:clipToPadding="false">
                <android.support.v7.widget.RecyclerView
                    android:layout_margin="@dimen/padding_medium"
                    android:id="@+id/recyclerview_pager"
                    android:layout_width="match_parent"
                   android:layout_height="@dimen/holder_height_medium"/>
</LinearLayout>

Moreover, I attach a rather unspectacular LinearLayoutManager like so:

 MyLayoutManager layoutManager
            = new MyLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
    recyclerViewPager.setLayoutManager(layoutManager);

The view holder in the adapter is very simple too:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:paddingTop="@dimen/layout_padding_small"
    android:paddingRight="@dimen/layout_padding_small"
    android:paddingLeft="@dimen/layout_padding_small">
.....
</LinearLayout>

Now I get the following behavior: When I am scrolled to one view, the item that is supposed to be visible in the padding area outside the recycler view is not yet rendered. Only when I start scrolling slightly, the item appears is rendered and displayed in the padding area as desired:

enter image description here enter image description here

How can I tell the recyclerview to layout the neighboring items before they are actually about to come into view? Using an item prefetch configuration on the LayoutManager did not help. I have searched the methods of the LayoutManager and did not find a good method to override exteding the.

Thanks in advance for any help, let me know if anything is still unclear.

Upvotes: 1

Views: 3950

Answers (1)

Amrish Kakadiya
Amrish Kakadiya

Reputation: 1023

You need to set clipToPadding=false to RecyclerView not to parent LinearLayout and also you can remove clipChildren

like this:

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

      <android.support.v7.widget.RecyclerView
                    android:layout_margin="@dimen/padding_medium"
                    android:id="@+id/recyclerview_pager"
                    android:layout_width="match_parent"
                    android:clipToPadding="false"
                    android:paddingEnd="40dp"
                    android:paddingLeft="40dp"
                    android:paddingRight="40dp"
                    android:paddingStart="40dp"
                   android:layout_height="@dimen/holder_height_medium"/>
</LinearLayout>

UPDATE I've added padding to recyclerview to make visible next item of position.

Upvotes: 1

Related Questions