Code Monkey home page Code Monkey logo

android-parallax-recyclerview's Introduction

android-parallax-recyclerview

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:-SNAPSHOT'
}

USAGE

(There is an example in example folder and in https://github.com/kanytu/example-parallaxrecycler)

  • Create a ViewHolder for your items
public class ExampleItemViewHolder extends RecyclerView.ViewHolder {
    public TextView textView;

    public ExampleItemViewHolder(View itemView) {
        super(itemView);
        textView = (TextView) itemView.findViewById(R.id.textView);
    }
}
  • Create a subclass of ParallaxRecyclerAdapter with the desired content
public class ExampleParallaxRecyclerAdapter extends ParallaxRecyclerAdapter<ExampleItemViewHolder> {
    private List<String> mContent;
    private Context mContext;

    public ExampleParallaxRecyclerAdapter(List<String> content, View header, RecyclerView view, boolean shouldClipView, Context context) {
        super(header, view, shouldClipView);
        mContent = content;
        mContext = context;
    }

    @Override
    public ExampleItemViewHolder onCreateItemViewHolder(ViewGroup parent) {
        final ExampleItemViewHolder holder = new ExampleItemViewHolder(LayoutInflater.from(mContext).inflate(R.layout.row_recyclerview, parent, false));
        //don't set listeners on onBindViewHolder. For more info check http://androidshenanigans.blogspot.pt/2015/02/viewholder-pattern-common-mistakes.html
        holder.textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(mContext, holder.textView.getText(), Toast.LENGTH_SHORT).show();
            }
        });
        return holder;
    }

    @Override
    public void onBindItemViewHolder(ExampleItemViewHolder holder, int position) {
        holder.textView.setText(mContent.get(position));
    }

    @Override
    public int getItemCountWithoutHeader() {
        return mContent.size();
    }
}
  • Create your object list and pass it to the constructor of ParallaxRecyclerAdapter
List<String> myContent = new ArrayList<String>(); // example content
View header = LayoutInflater.from(this).inflate(R.layout.myParallaxView, myRecycler, false);
ExampleParallaxRecyclerAdapter myAdapter = new ExampleParallaxRecyclerAdapter(myContent, header, recyclerView, false, getContext());
  • Parallax scroll listener
public class ExampleParallaxRecyclerAdapter extends ParallaxRecyclerAdapter<ExampleItemViewHolder> {

    // ...

    @Override
    public void onParallaxScroll(float percentage, float offset, View parallax) {
        // ...
    }

    // ...

}

RESULT

ParallaxListView

COOL EFFECTS YOU CAN DO WITH THIS LIBRARY

  • Transparent toolbar effect
public class ExampleParallaxRecyclerAdapter extends ParallaxRecyclerAdapter<ExampleItemViewHolder> {

    // ...

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

    // ...

}

ParallaxListView

Android Arsenal

License

Copyright (c) 2015 Pedro Oliveira

Licensed under the Apache License, Version 2.0

android-parallax-recyclerview's People

Contributors

bryant1410 avatar kanytu avatar tomxor avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.