android - Applauze like listview -
i trying make custom listview in ios app applauze.
i extended listview class , of ontouchevent tried detect movement of child rows , change heights on movement. topmost child has largest height compared other rows.
public class custview extends listview{ private float mlasttouchy; private int mactivepointerid; private boolean up=false; private boolean down=false; private final camera mcamera = new camera(); private final matrix mmatrix = new matrix(); private context context; private paint mpaint; public custview(context context, attributeset attrs) { super(context, attrs); this.context = context; this.setchildrendrawingorderenabled(true); } public custview(context context, attributeset attrs, int defstyle) { super(context, attrs, defstyle); // todo auto-generated constructor stub } @override protected boolean drawchild(canvas canvas, view child, long drawingtime) { // top left coordinates boolean istop = false; final int top = child.gettop(); final int bottom = child.getbottom(); child.setminimumheight(getheight()/3); bitmap bitmap = child.getdrawingcache(); bitmap cropbitmap; if (bitmap == null) { child.setdrawingcacheenabled(true); child.builddrawingcache(); bitmap = child.getdrawingcache(); } int belowe = (child.getheight()*2/3)+getpaddingtop(); int abovee = (child.getheight())+getpaddingtop(); mcamera.save(); if(up){ if (top>=belowe) { //make small istop = true; //canvas.scale(1.0f, 0.5f); cropbitmap = bitmap.createbitmap(bitmap, 0, 0, bitmap.getwidth(), bitmap.getheight()/2); child.setminimumheight(2); //child.setlayoutparams(layoutparams.wrap_content,layoutparams.wrap_content)); child.setpressed(true); log.e("chota", child.getmeasuredheight()+"true"+top); } else { //canvas.scale(1.0f,xy); cropbitmap = bitmap.createbitmap(bitmap, 0, 0, bitmap.getwidth(), bitmap.getheight()); //child.setlayoutparams(layoutparams.wrap_content,layoutparams.wrap_content)); //child.setminimumheight(4); log.e("bada", child.getmeasuredheight()+"false"+top); child.setpressed(false); }; } else{ if (bottom>abovee) { //make center row bigger istop = true; //canvas.scale(1.0f, 0.5f); cropbitmap = bitmap.createbitmap(bitmap, 0, 0, bitmap.getwidth(), bitmap.getheight()/2); child.setminimumheight(2); child.setpressed(true); log.e("bada", child.getmeasuredheight()+"true"+top); } else { //canvas.scale(1.0f,xy); cropbitmap = bitmap.createbitmap(bitmap, 0, 0, bitmap.getwidth(), bitmap.getheight()); //child.setminimumheight(getheight()/4); log.e("chota", child.getmeasuredheight()+"false"+top); child.setpressed(false); }; } mcamera.getmatrix(mmatrix); mcamera.restore(); // create , initialize paint object if (mpaint == null) { mpaint = new paint(); mpaint.setantialias(true); mpaint.setfilterbitmap(true); } mmatrix.postscale(1.0f, 1.5f); mmatrix.posttranslate(child.getleft(), top); canvas.drawbitmap(cropbitmap, mmatrix, mpaint); //log.e("up", "child"+top+" "+gettop()); return false; } /* (non-javadoc) * @see android.widget.abslistview#ontouchevent(android.view.motionevent) */ @override public boolean ontouchevent(motionevent ev) { // todo auto-generated method stub final int action = motioneventcompat.getactionmasked(ev); int invalid_pointer_id=65421385; switch (action) { case motionevent.action_down: { final int pointerindex = motioneventcompat.getactionindex(ev); // remember started (for dragging) mlasttouchy = motioneventcompat.gety(ev, pointerindex); // save id of pointer (for dragging) mactivepointerid = motioneventcompat.getpointerid(ev, 0); log.e("down", "down"); break; } case motionevent.action_move: { // find index of active pointer , fetch position final int pointerindex = motioneventcompat.findpointerindex(ev, mactivepointerid); final float y = motioneventcompat.gety(ev, pointerindex); // calculate distance moved final float dy = y - mlasttouchy; = dy<0; down = dy>0; //((myadapter)getlistadapter()).animate(fvi,top,bottom,getchildcount()); if(math.abs(dy)>10){ log.e("dist", "d-"+math.abs(dy)); invalidate(); } // remember touch position next move event mlasttouchy = y; log.e("move", "move"); break; } case motionevent.action_up: { mactivepointerid = invalid_pointer_id; log.e("up", "up"); break; } case motionevent.action_cancel: { mactivepointerid = invalid_pointer_id; break; } case motionevent.action_pointer_up: { final int pointerindex = motioneventcompat.getactionindex(ev); final int pointerid = motioneventcompat.getpointerid(ev, pointerindex); if (pointerid == mactivepointerid) { // our active pointer going up. choose new // active pointer , adjust accordingly. final int newpointerindex = pointerindex == 0 ? 1 : 0; mlasttouchy = motioneventcompat.gety(ev, newpointerindex); mactivepointerid = motioneventcompat.getpointerid(ev, newpointerindex); } break; } } return super.ontouchevent(ev); } /* (non-javadoc) * @see android.view.view#onscrollchanged(int, int, int, int) */ @override protected void onscrollchanged(int l, int t, int oldl, int oldt) { // todo auto-generated method stub super.onscrollchanged(l, t, oldl, oldt); } }
but problem drawchild function being called repeatedly saw in logs making listview less responsive. , best way apply animation each row?? if knows reason please let me know!!! thanks.
as doing lot of work in drawchild() function called repeatedly insert lagging thereby making listview less responsive. so, possibly can skip of drawchild() function calls based on timer or other logic. when handle sensor events in application. implementing should simple only.
for list view row animations can follow below link. best way animate write animation xmls , use them animate rows in listview:
http://karnshah8890.blogspot.kr/2013/04/listview-animation-tutorial.html
hope helps.
Comments
Post a Comment