android - Parallax header effect with RecyclerView -
i want alter listview have on utilize recyclerview
can create utilize of staggeredgridlayoutmanager
recyclerview not have ability add together header listview.
usually listview set empty view in header , set image below listview , translate bottom image scrolling of list create parallax
effect.
so out header how can create same parallax effect recyclerview
?
so today tried archive effect on recyclerview
. able since code much paste here github project , explain of key points of project.
https://github.com/kanytu/android-parallax-recyclerview
first need @ getitemviewtype
on recyclerview.adapter
class. methods defines type of view we're dealing with. type passed on oncreateviewholder
, there can inflate different views. did was: check if position first one. if inflate header, if not inflate normal row.
i've added customrelativelayout
clips view don't have problem dividers , rows getting on top of header.
from point seem know rest of logic behind it.
the final result was:
edit:
if need insert in adapter create sure notify right position adding 1 in notifyitemchanged/inserted
method. example:
public void additem(string item, int position) { mdata.add(position, item); notifyiteminserted(position + 1); //we have add together 1 notification position since don't want mess header }
another of import edit i've done scroll logic. mcurrentoffset
scheme using didn't work item insertion since offset alter if add together item. did was:
viewholder holder = findviewholderforposition(0); if (holder != null) ((parallaxrecycleradapter) getadapter()).translateheader(-holder.itemview.gettop() * 0.5f);
to test added postdelayed
runnable, started app, scrolled end, add together item in position 0, , scroll again. result was:
if looking other parallax effects can check other repo:
https://github.com/kanytu/android-parallax-listview
android recyclerview
No comments:
Post a Comment