GithubHelp home page GithubHelp logo

petittrung / android-parallax-recyclerview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kanytu/android-parallax-recyclerview

0.0 2.0 0.0 7.06 MB

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

License: Apache License 2.0

android-parallax-recyclerview's Introduction

android-parallax-recycleview

USAGE

  • Create your object list and pass it to the constructor of ParallaxRecyclerAdapter

     List<String> myContent = new ArrayList<String>(); //or another object list
     ParallaxRecyclerAdapter myAdapter = new ParallaxRecyclerAdapter(myContent); //pass the list to the constructor
    
  • Implement ParallaxRecyclerAdapter.RecyclerAdapterMethods.

     myAdapter.implementRecyclerAdapterMethods(new ParallaxRecyclerAdapter.RecyclerAdapterMethods() {
                             @Override
                             public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, 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 onCreateViewHolder(ViewGroup viewGroup, 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 getItemCount() {
                                     //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:

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

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

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) 2011 Pedro Oliveira

Licensed under the Apache License, Version 2.0

android-parallax-recyclerview's People

Contributors

kanytu avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.