android - Using an ImageView transform matrix instead of canvas.scale(float, float, float, float) -
i need change way scaling , moving imageview using matrix instead of calling canvas.scale(,,,,)
, cannot figure out proper calls this.
i had in scalelistener
listener class's onscale
method
public boolean onscale(scalegesturedetector detector) { ...//determining zoom level , pivot points offset child.zoom(scalefactor, zoomcenter[0], zoomcenter[1]); }
i had in child imageview's ondraw
method:
protected void ondraw(canvas canvas){ super.ondraw(canvas); canvas.scale(mscalefactor, mscalefactor, mposx, mposy); ... //do drawing here } public void zoom(float scalefactor, float zoomcenterx, float zoomcentery) { mscalefactor = scalefactor; mposx = zoomcenterx; mposy = zoomcentery; //redraw , remeasure mapview after zooming in invalidate(); }
i in onscale
method:
public boolean onscale(scalegesturedetector detector) { ...//calculating scale , offsets matrix m = child.getimagematrix(); m.reset(); m.postscale(scalefactor, scalefactor); m.posttranslate(zoomcenter[0], zoomcenter[1]); child.setscaletype(scaletype.matrix); child.setimagematrix(m); child.invalidate(); return true; }
but not appear doing anything...am missing here? tried using child.getmatrix()
instead through illegalstateexception saying matrix cannot modified. great!
okay figured out problem was. using setimagematrix(m)
apply entire imageview child class, instead of setting matrix canvas, this:
@override protected void ondraw(canvas canvas){ ... canvas.concat(transform);
}
i'm not sure difference between 2 though, if knows see difference bewteen imagematrix , matrix
edit: using canvas.setmatrix(transform)
messed scrolling; canvas.concat(transform)
recommended instead , trick
Comments
Post a Comment