detecting distance of scrolling in listview android -
detecting distance of scrolling in listview android -
is there way observe amount of distance scrolling motion takes place in listview.
i trying implement custom view container takes 2 views in vertical linearlayout or framelayout(still undecided) , simple manually gradually move/animate 2 kid views merging together/overlapping(like parallex effect).
once both kid views on screen want begin track motion of scrolling within listview , gradually move 2 kid view objects , stop moving them @ point.
i find illustration detects scrolling or downwards doesnt specificy amount of scrolling/distance has occured.
lv.setonscrolllistener(new onscrolllistener() { private int mlastfirstvisibleitem; @override public void onscrollstatechanged(abslistview view, int scrollstate) { } @override public void onscroll(abslistview view, int firstvisibleitem, int visibleitemcount, int totalitemcount) { if(mlastfirstvisibleitem<firstvisibleitem) { log.i("scrolling down","true"); } if(mlastfirstvisibleitem>firstvisibleitem) { log.i("scrolling up","true"); } mlastfirstvisibleitem=firstvisibleitem; } });
is there no interface callback such example:
public void onscrolling(int movementy){ //movementy value represents how much u have scrolled point of touching listview , applying scroll motion}
thanks in advance
see this one. want.
/** * created mariotaku on 14/10/22. */ public class listscrolldistancecalculator implements onscrolllistener { private scrolldistancelistener mscrolldistancelistener; private boolean mlistscrollstarted; private int mfirstvisibleitem; private int mfirstvisibleheight; private int mfirstvisibletop, mfirstvisiblebottom; private int mtotalscrolldistance; @override public void onscrollstatechanged(abslistview view, int scrollstate) { if (view.getcount() == 0) return; switch (scrollstate) { case scroll_state_idle: { mlistscrollstarted = false; break; } case scroll_state_touch_scroll: { final view firstchild = view.getchildat(0); mfirstvisibleitem = view.getfirstvisibleposition(); mfirstvisibletop = firstchild.gettop(); mfirstvisiblebottom = firstchild.getbottom(); mfirstvisibleheight = firstchild.getheight(); mlistscrollstarted = true; mtotalscrolldistance = 0; break; } } } public int gettotalscrolldistance() { homecoming mtotalscrolldistance; } @override public void onscroll(abslistview view, int firstvisibleitem, int visibleitemcount, int totalitemcount) { if (totalitemcount == 0 || !mlistscrollstarted) return; final view firstchild = view.getchildat(0); final int firstvisibletop = firstchild.gettop(), firstvisiblebottom = firstchild.getbottom(); final int firstvisibleheight = firstchild.getheight(); final int delta; if (firstvisibleitem > mfirstvisibleitem) { mfirstvisibletop += mfirstvisibleheight; delta = firstvisibletop - mfirstvisibletop; } else if (firstvisibleitem < mfirstvisibleitem) { mfirstvisiblebottom -= mfirstvisibleheight; delta = firstvisiblebottom - mfirstvisiblebottom; } else { delta = firstvisiblebottom - mfirstvisiblebottom; } mtotalscrolldistance += delta; if (mscrolldistancelistener != null) { mscrolldistancelistener.onscrolldistancechanged(delta, mtotalscrolldistance); } mfirstvisibletop = firstvisibletop; mfirstvisiblebottom = firstvisiblebottom; mfirstvisibleheight = firstvisibleheight; mfirstvisibleitem = firstvisibleitem; } public void setscrolldistancelistener(scrolldistancelistener listener) { mscrolldistancelistener = listener; } public static interface scrolldistancelistener { void onscrolldistancechanged(int delta, int total); } }
android listview android-listview
Comments
Post a Comment