Android - View is moving out of screen post rotation -


hi i'm trying perform translate, scale , rotate on view (framelayout) in android.

in brief, i've fresco's simpledraweeview inside framelayout, fresco not supporting matrix transformations, alternative put in framelayout , doing translation, rotation , scaling.

i've extended framelayout here..

public class interactiveframelayout extends framelayout {  private viewtransformer mviewtransformer;  public interactiveframelayout(context context) {     super(context);     init(context); }  public interactiveframelayout(context context, attributeset attrs) {     super(context, attrs);     init(context); }  public interactiveframelayout(context context, attributeset attrs, int defstyle) {     super(context, attrs, defstyle);     init(context); }  private void init(context context) {     // determine dimensions of 'earth' image     int baseviewwidth = (int) getresources().getdimension(r.dimen.animation_image_size);     int baseviewheight = (int) getresources().getdimension(r.dimen.animation_image_size);      // setup gesture detectors     mviewtransformer = new viewtransformer(this, baseviewwidth, baseviewheight); }  public boolean ontouchevent(motionevent event) {     return mviewtransformer.ontouchevent(event) || super.ontouchevent(event); } 

}

below class takes view , related viewtransformations.

public class viewtransformer {  private view mview;  private vector2d position; private float scale = 1; private float angle = 0;  private touchmanager touchmanager = new touchmanager(2);  public viewtransformer(view view, int viewwidth, int viewheight) {     mview = view;      position = new vector2d();     position.set(viewwidth / 2, viewheight / 2); }  public boolean ontouchevent(motionevent event) {     try {         touchmanager.update(event);          if (touchmanager.getpresscount() == 1) {             position.add(touchmanager.movedelta(0));             viewaffineoperation.moveviewto(mview, position.getx(), position.gety());         }         else {             if (touchmanager.getpresscount() == 2) {                 vector2d current = touchmanager.getvector(0, 1);                 vector2d previous = touchmanager.getpreviousvector(0, 1);                 float currentdistance = current.getlength();                 float previousdistance = previous.getlength();                  if (previousdistance != 0) {                     scale *= currentdistance / previousdistance;                     viewaffineoperation.scaleviewby(mview, scale);                 }                  angle -= vector2d.getsignedanglebetween(current, previous);                 viewaffineoperation.rotateviewby(mview, getdegreesfromradians(angle));             }         }          mview.invalidate();     }     catch(throwable t) {         // lazy...     }     return true; }  private static float getdegreesfromradians(float angle) {     return (float)(angle * 180.0 / math.pi); }  public float getscale() {     return scale; }  public float getrotationdegrees() {     return angle; } 

}

and one

public class viewaffineoperation {  public static void moveviewto(view view, float focusx, float focusy) {      viewgroup.layoutparams layoutparams = view.getlayoutparams();      int midpointx = layoutparams.width >> 1;     int midpointy = layoutparams.height >> 1;     float dx = (focusx - midpointx);     float dy = (focusy - midpointy);      view.settranslationx(view.gettranslationx() + dx);     view.settranslationy(view.gettranslationy() + dy); }  public static void scaleviewby(view view, float scalefactor) {     view.setscalex(scalefactor);     view.setscaley(scalefactor); }  public static void rotateviewby(view view, float degrees) {     view.setrotation(degrees); } 

}

the key problem in

view.settranslationx(view.gettranslationx() + dx); view.settranslationy(view.gettranslationy() + dy); 

this 1 promising thing i've found in stack on flow.. rotate , scale view based on 1 handle in android

thanks ton in advance.

@sasha salauyou i'm trying reach me in finding solution.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -