A strange thing About ImageView in Android -


recently,i complete own imageview. can draged or zoomed,but when install apk phone,this imageview shake when want zoom.(i not @ english,sorry).thanks help

the following subclass of imageview:

      public class myimageview extends imageview {  private mode mode = mode.none;  private pointf startpoint = new pointf();  private float distance = 0;  private float scale;  public myimageview(context context) {     super(context);     this.setpadding(10, 10, 10, 10);     this.setscaletype(scaletype.fit_xy);     this.setimageresource(r.drawable.emoji_18); }  @override public boolean ontouchevent(motionevent event) {     if (!isenabled())         return false;     switch (event.getaction() & motionevent.action_mask) {     case motionevent.action_down:         mode = mode.drag;          startpoint.set(event.getrawx(), event.getrawy());         break;     case motionevent.action_move:         if (mode == mode.drag) {             drag(event);         }         if (mode == mode.zoon_rotation && event.getpointercount() == 2) {             zoon(event);         }         break;     case motionevent.action_pointer_down:         distance = distance(event);         scale = this.getscalex();         mode = mode.zoon_rotation;         break;     case motionevent.action_pointer_up:         mode = mode.none;         break;     case motionevent.action_up:     default:         break;     }     return true; }  private void zoon(motionevent event) {     float currentdistance = distance(event);     float currentscale = currentdistance / distance;     currentscale = scale * currentscale;     this.setscalex(currentscale);     this.setscaley(currentscale);  }  private void drag(motionevent event) {     pointf endpoint = new pointf();     endpoint.set(event.getrawx(), event.getrawy());     float dx = endpoint.x - startpoint.x;     float dy = endpoint.y - startpoint.y;     startpoint.set(endpoint);     this.settranslationx(this.gettranslationx() + dx);     this.settranslationy(this.gettranslationy() + dy);     this.invalidate(); }  private float distance(motionevent event) {     float dx = event.getx(0) - event.getx(1);     float dy = event.gety(0) - event.gety(1);     return floatmath.sqrt(dx * dx + dy * dy); }  private enum mode {     none, drag, zoon_rotation;  }      } 

the following mainactivity:

           public class mainactivity extends activity {  private framelayout framelayout; @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     this.setcontentview(r.layout.activity_main);     framelayout=(framelayout) findviewbyid(r.id.framelayout);     myimageview myview= new myimageview(this);     framelayout.addview(myview , 300 ,300);     myview= new myimageview(this);     framelayout.addview(myview , 300 , 300);  }       } 

the following layout:

 framelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"  android:id="@+id/framelayout" > 


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -