Skip to content

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

License

Notifications You must be signed in to change notification settings

xmartlabs/android-parallax-recyclerview

 
 

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%