android - How to apply a transformation to View? -


i have custom view overridden ondraw:

protected void ondraw(canvas canvas) {     canvas.drawpath(m_path, m_paint); } 

i want make possible pan/scale/rotate view. , not want redraw every time user moves finger. idea apply transformation matrix view in response user gestures.

i know there method imageview.setimagematrix seems need, have not imageview, custom view.

in ios, used calayer , mylayer.affinetransform = cgaffinetransformmake....

how suggest handle in android?

if drawing path, can apply matrix (as android calls affine transform) path:

on user interaction, update matrix, view call:

        m_path.transform(m_matrix, m_path_draw); 

see path#transform | android developers

and in ondraw(), call:

        canvas.drawpath(m_path_draw, m_paint); 

alternatively, canvas has setmatrix() method:

        canvas.save();         canvas.setmatrix(m_matrix);         canvas.drawpath(m_path, m_paint);         canvas.restore(); 

whichever method use, recommend having matrix member variable construct once during custom view construction.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -