How to set a border for android Imageview in Longpress? -


in android application want set border imageview when long pressed. want remove same(border) when user releases view. please anyone, me in this?

@override public boolean ontouchevent(motionevent event) {      switch (event.getaction()) {         case motionevent.action_down: {             mtouchdownx = (int) event.getx();             mtouchdowny = (int) event.gety();             break;         }         case motionevent.action_move: {             int x = (int) event.getx();             int y = (int) event.gety();              if (mdraggeditem >= 0) {                 setdraggeditemposition(x, y);                 int index = getindexfromcoordinates(x, y);                 if (index == mdraggeditem || index < 0) break;                  if (index < mdraggeditem) {                     (int = index; < mdraggeditem; i++) {                         moveviewtoposition(i, i+1);                     }                     (int = mdraggeditem-1; >= index; i--) {                         view view = mgridmap.get(i);                         mgridmap.put(i+1, view);                     }                 } else {                     (int = index; > mdraggeditem; i--) {                         moveviewtoposition(i, i-1);                     }                     (int = mdraggeditem+1; <= index; i++) {                         view view = mgridmap.get(i);                         mgridmap.put(i-1, view);                     }                 }                 mlog.i("ontouchevent - action_move - mdraggeditem: "+mdraggeditem+" index: "+index);                 mgridmap.put(index, mdraggedview);                 mdraggeditem = index;             }             break;         }         case motionevent.action_up: {             if (mdraggeditem >= 0) {                 point xy = getcoordinatesfromposition(mdraggeditem);                 mdraggedview.layout(xy.x, xy.y, xy.x+mchildsize, xy.y+mchildsize);                 mdraggedview.clearanimation();                 mdraggedview.setpadding(0, 0, 0, 0);                 setonclicklistener(this);                 invalidate();                 mrearrangelistener.onrearrange(mgridmap);             }             mdraggeditem = -1;             for(int i=0;i<mgridmap.size();i++)             {             string tag = mgridmap.get(i).gettag().tostring();             }             break;         }     }      return super.ontouchevent(event);  }  @override public boolean onlongclick(view v) {      int index = getindexfromcoordinates(mtouchdownx, mtouchdowny);     if (index >= 0) {         // animate item enabling drag.         mdraggeditem = index;         mdraggedview = mgridmap.get(index);         mdraggedview.setpadding(2, 2, 2, 2);         mdraggedview.setbackgroundcolor(color.white);         setdraggeditemposition(mtouchdownx, mtouchdowny);         animatedragged();     }      return true; } 

you can add white border of thickness 2 way around imageview via onlongclicklistener follows:

imageview.setonlongclicklistener(new onlongclicklistener() {          @override         public boolean onlongclick(view v) {               imageview.setpadding(2, 2, 2, 2);               imageview.setbackgroundcolor(color.white);             return true;         }     }); 

you can via ontouchlistener well:

imageview.setontouchlistener(new ontouchlistener() {         @override        public boolean ontouch(view v, motionevent event) {             switch(event){             case motionevent.action_down:                  imageview.setpadding(2, 2, 2, 2);                  break;             case motionevent.action_up:                  imageview.setpadding(0, 0, 0, 0);                  break;             }           return false;     } 

you potentially combine 2 set padding in onlongclicklistener, , remove padding in motionevent.action_up section of ontouchlistener.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -