Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/angeloavv/recyclerviewflipper

A custom ViewFlipper to dinamically add views at runtime without render-loss time
https://github.com/angeloavv/recyclerviewflipper

Last synced: about 2 months ago
JSON representation

A custom ViewFlipper to dinamically add views at runtime without render-loss time

Awesome Lists containing this project

README

        

# RecyclerViewFlipper
A custom ViewFlipper to dinamically add views at runtime without render-loss time

The RecyclerViewFlipper is a Custom ViewFlipper that allows you to scroll between an infinite number of Views without render-loss time. The component stores a double-ended queue (deque) in order to pre-load the views that need to be shown. In this way, you could dinamically add an infinite (we suppose to!) odd number of views without wasting your time in pre-rendering phases while scrolling.
The RecyclerViewFlipper also supports animations as its superclass ViewFlipper, and distorts the way of seeing the views since they are handled as a stack, but stored as a deque.
This library also avoids OutOfMemory errors due to a lot of views loaded inside the ViewFlipper, because in this case the views are added at runtime with a fixed number of loaded views per time.

## How to use it

In your layout:


and in your Java file:

View firstView = View.inflate(this, FIRST_VIEW, null);
View secondView = View.inflate(this, SECOND_VIEW, null);
View thirdView = View.inflate(this, THIRD_VIEW, null);

ArrayList views = new ArrayList<>();
views.add(firstView);
views.add(secondView);
views.add(thirdView);

mRecyclerViewFlipper = (RecyclerViewFlipper) findViewById(ID_VIEWFLIPPER);
mRecyclerViewFlipper.initializeComponents(views);
mRecyclerViewFlipper.setRecycleViewFlipperRequest(this);

your activity must implement RecyclerViewFlipperRequest\ , where T could be a class that inherits from View and these two methods deal the runtime generation of the dynamic view

@Override
public View requestLeftItem() {
View newView = View.inflate(this, SECOND_VIEW, null);
Button btn = (Button) newView.findViewById(R.id.btn);
btn.setText(String.valueOf(mCounter++));

return newView;
}

@Override
public View requestRightItem() {
View newView = View.inflate(this, SECOND_VIEW, null);
Button btn = (Button) newView.findViewById(R.id.btn);
btn.setText(String.valueOf(mCounter--));

return newView;
}

In this example I've inflated the same view changing the content of the button, but you can do it in very different ways, like putting it inside a Stack while you process it and so on.
Keep in mind that the preprocessing deque is defined when you call mRecyclerViewFlipper.initializeComponents(views);
the queue will keep a number of K views per time, where K is the size of the List

If you want to see an example of the library in action, please [watch a demo here](https://youtu.be/jqfqNujkTfo)