An adapter which could be used to achieve a parallax effect on RecyclerView.

Overview

android-parallax-recycleview

Integration

Step 1. Add the JitPack repository to your build file

repositories {
    maven {
        url "https://jitpack.io"
    }
}

Step 2. Add the dependency

dependencies {
	compile 'com.github.kanytu:android-parallax-recyclerview:v1.7'
}

USAGE

(Example project - https://github.com/kanytu/example-parallaxrecycler)

  • Create your object list and pass it to the constructor of ParallaxRecyclerAdapter
List<String> myContent = new ArrayList<String>(); // or another object list
ParallaxRecyclerAdapter<String> adapter = new ParallaxRecyclerAdapter<String>(content) {
            @Override
            public void onBindViewHolderImpl(RecyclerView.ViewHolder viewHolder, ParallaxRecyclerAdapter<String> adapter, int i) {
              // If you're using your custom handler (as you should of course) 
              // you need to cast viewHolder to it.
              ((MyCustomViewHolder) viewHolder).textView.setText(myContent.get(i)); // your bind holder routine.
            }

            @Override
            public RecyclerView.ViewHolder onCreateViewHolderImpl(ViewGroup viewGroup, final ParallaxRecyclerAdapter<String> adapter, int i) {
              // Here is where you inflate your row and pass it to the constructor of your ViewHolder
              return new MyCustomViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.myRow, viewGroup, false));
            }

            @Override
            public int getItemCountImpl(ParallaxRecyclerAdapter<String> adapter) {
              // return the content of your array
              return myContent.size();
            }
        };
  • Now we set the parallax header. You need to pass the RecyclerView too to implement the scroll listeners.
myAdapter.setParallaxHeader(LayoutInflater.from(this).inflate(
    R.layout.myParallaxView, myRecycler, false), myRecyclerView);

There a few other listeners you can implement:

// Event triggered when you click on a item of the adapter.
void onClick(View v, int position); 

// Event triggered when the parallax is being scrolled.
void onParallaxScroll(float percentage, float offset, View parallax); 

RESULT

ParallaxListView

COOL EFFECTS YOU CAN DO WITH THIS LIBRARY

  • Transparent toolbar effect
@Override
public void onParallaxScroll(float percentage, float offset, View parallax) {
  Drawable c = mToolbar.getBackground();
  c.setAlpha(Math.round(percentage * 255));
  mToolbar.setBackground(c);
}

ParallaxListView

Android Arsenal

License

Copyright (c) 2014 Pedro Oliveira

Licensed under the Apache License, Version 2.0

Comments
  • Add a custom row between header image & recyclerveiw

    Add a custom row between header image & recyclerveiw

    hello,

    Thankyou for the library. It's working fine. The thing I want to achieve is add a custom row or relative layout between header image & recyclerview. I have tried following this example http://stackoverflow.com/questions/26568087/parallax-header-effect-with-recyclerview#text. The example where the guy inserted a text " Hi, I'm new here " before test 1 & after header image.

    The problem with my code is the first element of recylcerview is getting replaced by the custom row that I have created. This is the output http://s11.postimg.org/w31cmp3qb/detail.jpg . the "mobileapp" is the data in the recyclerview .mobileapp 0 is getting hidden or replaced by " MobileApp 0".

    This is my code I am using

    adapter.implementRecyclerAdapterMethods(new ParallaxRecyclerAdapter.RecyclerAdapterMethods() { @Override public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) { if (i == 0) { ((ViewHolder) viewHolder).title.setText(“MobileApp” + i); ((ViewHolder) viewHolder).ct.setText(“test”); } else if (i > 0) { ((ViewHolder) viewHolder).title2.setText((“mobileapp” + i); ((ViewHolder) viewHolder). title3.setText(“”); }

            }
    
            @Override
            public RecyclerView.ViewHolder onCreateViewHolder(
                    ViewGroup viewGroup, final int i) {
                final ViewHolder holder;
                if (i == 3) {
                    holder = new ViewHolder(getLayoutInflater().inflate(
                            R.layout.row_recylceview_firstcard, viewGroup,
                            false), i);
    
                } else {
                    holder = new ViewHolder(getLayoutInflater().inflate(
                            R.layout.row_recyclerview, viewGroup, false), i);
                                    }
                return holder;
            }
    
            @Override
            public int getItemCount() {
                return content.size();
            }
    

    });

    please help

    opened by aniruddhasm 16
  • ParallaxRecyclerAdapter implements RecyclerAdapterMethods

    ParallaxRecyclerAdapter implements RecyclerAdapterMethods

    Wouldn't it be more appropriate if instead of having a method that asks for the implementation, to have them overriden?

    I mean, instead of this:

    ParallaxRecyclerAdapter<String> adapter = new ParallaxRecyclerAdapter<>(content);
    adapter.implementRecyclerAdapterMethods(new ParallaxRecyclerAdapter.RecyclerAdapterMethods() {
        // implemented methods
    }
    

    This:

    ParallaxRecyclerAdapter<String> adapter = new ParallaxRecyclerAdapter<>(content) {
        // implemented methods
    }
    
    opened by bryant1410 7
  • onCreateViewHolderImpl never called

    onCreateViewHolderImpl never called

    Hi I 'm using the adapter in a Fragmet and I can not get it to work, the resulting view is empty.

    public class PlaylistPreviewFragment extends Fragment {
    
        protected RecyclerView recyclerPlaylistTracks;
    
        @Nullable
        @Override
        public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
            super.onCreateView(inflater, container, savedInstanceState);
            View view = inflater.inflate(R.layout.playlist_preview_fragment,container,false);
            recyclerPlaylistTracks = (RecyclerView)view.findViewById(R.id.playlist_tracks);
    
            final List<String> content = new ArrayList<>();
            for (int i = 0; i < 50; i++) {
                content.add("item " + i);
            }
    
            final ParallaxRecyclerAdapter<String> adapter = new ParallaxRecyclerAdapter<String>(content) {
                @Override
                public void onBindViewHolderImpl(RecyclerView.ViewHolder viewHolder, ParallaxRecyclerAdapter<String> adapter, int i) {
                    TrackViewHolder trackViewHolder = (TrackViewHolder)viewHolder;
                    trackViewHolder.setTitle(content.get(i));
                }
    
                @Override
                public RecyclerView.ViewHolder onCreateViewHolderImpl(ViewGroup viewGroup, final ParallaxRecyclerAdapter<String> adapter, int i) {
                    return new TrackViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.playlist_track_layout, viewGroup, false));
                }
    
                @Override
                public int getItemCountImpl(ParallaxRecyclerAdapter<String> adapter) {
                    return content.size();
                }
            };
    
            adapter.setOnClickEvent(new ParallaxRecyclerAdapter.OnClickEvent() {
                @Override
                public void onClick(View v, int position) {
                    Toast.makeText(getActivity(), "You clicked '" + position + "'", Toast.LENGTH_SHORT).show();
                }
            });
    
            recyclerPlaylistTracks.setLayoutManager(new LinearLayoutManager(getActivity()));
            View header = inflater.inflate(R.layout.playlist_tracks_header, recyclerPlaylistTracks, false);
            adapter.setParallaxHeader(header, recyclerPlaylistTracks);
            adapter.setData(content);
            recyclerPlaylistTracks.setAdapter(adapter);
    
    
            return view;
        }
    
    
    
        static class TrackViewHolder extends RecyclerView.ViewHolder{
    
            private TextView title;
    
            public TrackViewHolder(View itemView) {
                super(itemView);
                title = (TextView)itemView.findViewById(R.id.title);
            }
    
            public void setTitle(String title) {
                this.title.setText(title);
            }
    
            public String getTitle() {
                return title.toString();
            }
        }
    }
    

    can you help me please?

    onCreateViewHolderImpl and onBindViewHolderImpl are never called.

    Thanks and greetings

    opened by sergio11 6
  • ScrollToPosition make the header dissapear

    ScrollToPosition make the header dissapear

    when I do scroll with my fingers everything works fine, but if I want to do it programmatic and for example go to the last element with something like:

    recyclerview.scrollToPosition(adapter.getItemCount()-1);
    

    it doesn't work, even with the sample code on this repo, it scrolls but header dissapear when i scroll up again to the same place.

    opened by chriscoderdr 6
  • Custom Viewholder implementation

    Custom Viewholder implementation

    I'm having mu custom viewholder which extends RecyclerView.ViewHolder and I'm dynamically updating the recyclerview. It's showing error while Overriding onBindViewHolder. I have used an Interface 'AccountInfo' instead of 'String' type.

    Here's my Adapter code:

    public class AccountDetailAdapter extends ParallaxRecyclerAdapter<AccountDetailAdapter.AccountDetailViewHolder> {
    
      private LayoutInflater inflater;
      private Context context;
    
      List<AccountInfo> data = Collections.emptyList();
    
      public AccountDetailAdapter(Context context, final List<AccountInfo> data) {
        super(new ArrayList<AccountInfo>());
        this.context = context;
        inflater = LayoutInflater.from(context);
        this.data = data;
        implementRecyclerAdapterMethods(new RecyclerAdapterMethods() {
    
            @Override
            public void onBindViewHolder(AccountDetailViewHolder viewHolder, int i) {
                AccountInfo current = data.get(i);
                viewHolder.pName.setText(current.personName);
                viewHolder.pBalance.setText(current.personBalance);
                viewHolder.pIcon.setImageDrawable(current.personIconId);
            }
    
            @Override
            public AccountDetailViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
                View view = inflater.inflate(R.layout.account_row, viewGroup, false);
                AccountDetailViewHolder holder = new AccountDetailViewHolder(view);
                return holder;
            }
    
            @Override
            public int getItemCount() {
                return data.size();
            }
         });
      }
    
       class AccountDetailViewHolder extends RecyclerView.ViewHolder {
    
            TextView pName;
            TextView pBalance;
            ImageView pIcon;
    
            public AccountDetailViewHolder(View itemView) {
                super(itemView);
    
                pName = (TextView) itemView.findViewById(R.id.personName);
                pBalance = (TextView) itemView.findViewById(R.id.personBalance);
                pIcon = (ImageView) itemView.findViewById(R.id.personIconId);
                itemView.setClickable(true);
            }
    
        }
    }
    

    And in calling super(new ArrayList()), it says "ParallaxRecyclerAdapter (java.util.List<com.example.myapp>.AccountDetailAdapter.AccountDetailViewHolder) in ParallaxRecyclerAdapter cannot be applied to java.util.ArrayList<com.example.myapp>.AccountInfo.

    selection_004

    How do I port to my own ViewHolder?

    opened by nowke 6
  • Error when I try to import the library

    Error when I try to import the library

    Error:A problem occurred configuring project ':app'.

    Could not resolve all dependencies for configuration ':app:_debugCompile'. Could not find com.github.kanytu:android-parallax-recyclerview:v1.3. Searched in the following locations: https://jcenter.bintray.com/com/github/kanytu/android-parallax-recyclerview/v1.3/android-parallax-recyclerview-v1.3.pom https://jcenter.bintray.com/com/github/kanytu/android-parallax-recyclerview/v1.3/android-parallax-recyclerview-v1.3.jar file:/C:/Users/Maxime/AppData/Local/Android/sdk/extras/android/m2repository/com/github/kanytu/android-parallax-recyclerview/v1.3/android-parallax-recyclerview-v1.3.pom file:/C:/Users/Maxime/AppData/Local/Android/sdk/extras/android/m2repository/com/github/kanytu/android-parallax-recyclerview/v1.3/android-parallax-recyclerview-v1.3.jar file:/C:/Users/Maxime/AppData/Local/Android/sdk/extras/google/m2repository/com/github/kanytu/android-parallax-recyclerview/v1.3/android-parallax-recyclerview-v1.3.pom file:/C:/Users/Maxime/AppData/Local/Android/sdk/extras/google/m2repository/com/github/kanytu/android-parallax-recyclerview/v1.3/android-parallax-recyclerview-v1.3.jar Required by: mytripeazzy:app:unspecified

    opened by max02100 5
  • setOnClickEvent() never called

    setOnClickEvent() never called

    I simply want to detect clicks over parallaxAdapter items.

    Maybe I'm missing something, I can't get setOnClickEvent() to work.

    mAdapter.setOnClickEvent(new ParallaxRecyclerAdapter.OnClickEvent() { @Override public void onClick(View view, int i) { //This is never called } });

    Please note that mAdapter.setOnParallaxScroll(new ParallaxRecyclerAdapter.OnParallaxScroll() ... ) works perfectly and I have onBindViewHolderImpl(), onCreateViewHolderImpl(), etc. implemented and working inside the adapter impl

    opened by shineangelic 4
  • How I can use your adapter with dynamic data

    How I can use your adapter with dynamic data

    I am trying to create an instance of your adapter by extending it to load arraylist of custom objects from the internet, initially it ll have nothing but later it ll be filled with data. snap 2015-02-27 at 10 03 01 I get this error saying 'no default constructor available' what would be the optimal way to load nothing initially and then load data inside the parallax from the internet, thanks for your reply in advance

    opened by slidenerd 4
  • ScrollListener never called

    ScrollListener never called

    Hi. Have you tried to use the onScrollListener on the RecyclerView with this adapter? In my case it is never called! For the rest everything works fine.

    opened by DenisBronx 4
  • Getting percentage (and offset) wrong

    Getting percentage (and offset) wrong

    The problem is quite simple to explain, but I don't know how to solve it... -> When I start scrolling the percentage and offset are okay, but when I pass the 100% (in the log it reaches 0.99722224) it goes down to 54% and start going up again as I keep scrolling down.

    opened by facundomedica 3
  • Parallax header bug inside viewpager

    Parallax header bug inside viewpager

    Hi, I've put the recyclerview with parallax header inside a viewpager which have 4 fragment (0 - 3). The problem occurs when the recyclerview is scrolled until the image collapsed, then the viewpager change position from 0 - 2. When i return back to the fragment (position 0) and scrolled back up the image are gone (white blank).

    I set the adapter.setParallaxHeader() inside the onCreateView. Is this a bug or am i putting it in the wrong place? Thank you.

    opened by bdaykid 3
  • Upgrade gradle so that Android Studio 3.2 can open the project.

    Upgrade gradle so that Android Studio 3.2 can open the project.

    Hi Kanyu,

    I have update the project by upgrade to the minimal gradle version that could be run by Android Studio 3.2. Hopes you could check it out and merge it so that it could be easier for future maintainability with the newer Android Studio.

    Thanks, Elye

    opened by elye 0
  • Dependency issue

    Dependency issue

    In older version gradles project works fine. But today i migrated to android studio 3 with gradle version 3.1.4. After migration same dependency added in build.gradle file. but ParallaxRecyclerAdapter class not getting resolved. pls help me.

    opened by bijinelectro 0
  • overlay a header to a description element

    overlay a header to a description element

    https://github.com/kanytu/android-parallax-recyclerview/blob/cad6b8d619a3d2d87efa35e7a8f456f55b120dc5/library/src/main/java/com/poliveira/parallaxrecyclerview/ParallaxRecyclerAdapter.java#L99

    Hello, guys I found such a bug:

    1. Make the description under the header very large
    2. Scroll so that header disappears

    header disappears, and then abruptly appears and the description is superimposed on it (see image) the mRecyclerView.computeVerticalScrollOffset() on 99 line produces a value much larger than mHeader.getHeight()

    if you write such a piece of code, it will work out correctly

    super.onScrolled(recyclerView, dx, dy);
    if (mHeader != null) {
      float verticalScrollOffset = MathUtils.min(mRecyclerView.computeVerticalScrollOffset(), 
                                                                        mHeader.getHeight());
      translateHeader(mRecyclerView.getLayoutManager().getChildAt(0) == mHeader ?
                                verticalScrollOffset : mHeader.getHeight());
    }
    

    image

    opened by SergeyKarleev 0
Owner
Pedro Oliveira
Pedro Oliveira
Kotlin way of building RecyclerView Adapter 🧩. You do not have to write RecyclerView Adapters again and again and suffer from handling of different view types. Kiel will help you.

Kiel Kiel is a RecyclerView.Adapter with a minimalistic and convenient Kotlin DSL which provides utility on top of Android's normal RecyclerView.Adapt

ibrahim yilmaz 370 Jan 2, 2023
Android library defining adapter classes of RecyclerView to manage multiple view types

RecyclerView-MultipleViewTypeAdapter RecyclerView adapter classes for managing multiple view types Release Note [Release Note] (https://github.com/yqr

Yoshihito Ikeda 414 Nov 21, 2022
ListView with blur/parallax/sticky capabilities

BlurStickyHeaderListView What is BlurStickyHeaderListView? It is a custom ListView with a header that displays pictures from an URL. It then adds a ni

null 129 Oct 26, 2022
An Android Animation library which easily add itemanimator to RecyclerView items.

RecyclerView Animators RecyclerView Animators is an Android library that allows developers to easily create RecyclerView with animations. Please feel

Daichi Furiya 11.2k Jan 5, 2023
RecyclerView extension library which provides advanced features. (ex. Google's Inbox app like swiping, Play Music app like drag and drop sorting)

Advanced RecyclerView This RecyclerView extension library provides Google's Inbox app like swiping, Play Music app like drag-and-drop sorting and expa

Haruki Hasegawa 5.2k Dec 23, 2022
Pumped up RecyclerView

##Description This is an attempt to make RecyclerView easier to use. Features built in: ProgressBar while adapter hasn't been set EmptyView if adapter

Anton Malinskiy 2.6k Jan 5, 2023
A very easy-to-use and non-intrusive implement of Swipe to dismiss for RecyclerView.

RecyclerViewSwipeDismiss A very easy-to-use and non-intrusive implement of Swipe to dismiss for RecyclerView. Preview How to use Add these lines to yo

xcodebuild 431 Nov 23, 2022
. Android library that integrate sticky section headers in your RecyclerView

recyclerview-stickyheaders Recyclerview-stickyheaders is an Android library that makes it easy to integrate section headers in your RecyclerView. Thes

null 968 Nov 10, 2022
Android library providing simple way to control divider items (ItemDecoration) of RecyclerView

RecyclerView-FlexibleDivider Android library providing simple way to control divider items of RecyclerView Release Note [Release Note] (https://github

Yoshihito Ikeda 2.4k Dec 18, 2022
A Fast Scroller for the RecyclerView world!

RecyclerViewFastScroller The RecyclerViewFastScroller is a widget that can be added to a layout and connected to a RecyclerView for fast scrolling. Th

Daniel Smith 1.1k Dec 19, 2022
*** WARNING: This library is no longer maintained *** An easy way to add a simple 'swipe-and-do-something' behavior to your `RecyclerView` items. Just like in Gmail or Inbox apps.

SwipeToAction An easy way to add a simple 'swipe-and-do-something' behavior to your RecyclerView items. Just like in Gmail or Inbox apps. Integration

Victor Calvello 223 Nov 16, 2022
ItemDecoration for RecyclerView using LinearLayoutManager for Android

RecyclerItemDecoration RecyclerItemDecoration allows you to draw divider between items in recyclerview with multiple ViewType without considering item

magiepooh 328 Dec 27, 2022
[UNMAINTAINED] Sticky Headers decorator for Android's RecyclerView

This project is no longer being maintained sticky-headers-recyclerview This decorator allows you to easily create section headers for RecyclerViews us

timehop 3.7k Dec 31, 2022
An Android staggered grid view which supports multiple columns with rows of varying sizes.

AndroidStaggeredGrid ##Notice - Deprecated - 09-2015 This library has been deprecated. We will no longer be shipping any updates or approving communit

Etsy, Inc. 4.8k Dec 29, 2022
A GridView which can addHeaderView and addFooterView

Please follow me on GitHub, I need your support Github: https://github.com/liaohuqiu twitter: https://twitter.com/liaohuqiu 中文版文档 GridView with Header

Huqiu Liao 1.3k Nov 30, 2022
Android library to achieve in an easy way, the behaviour of the home page in the Expedia app, with a pair of auto-scroll circular parallax ListViews.

ListBuddies This library is not maintained anymore and there will be no further releases Android library of a pair of auto-scroll circular parallax Li

JPARDOGO 970 Dec 29, 2022
Android library to achieve in an easy way, the behaviour of the home page in the Expedia app, with a pair of auto-scroll circular parallax ListViews.

ListBuddies This library is not maintained anymore and there will be no further releases Android library of a pair of auto-scroll circular parallax Li

JPARDOGO 970 Dec 29, 2022
An Android view for displaying repeated continuous side scrolling images. This can be used to create a parallax animation effect.

Scrolling Image View An Android view for displaying repeated continuous side scrolling images. This can be used to create a parallax animation effect.

Q42 1.8k Dec 27, 2022
Parallax everywhere is a library with alternative android widgets with parallax effects.

Parallax Everywhere# Parallax everywhere (PEW) is a library with alternative android views using parallax effects. Demo You can try the demo app on go

fmSirvent 712 Nov 14, 2022