How to drag and align an item in Android custom view? -


i created custom view add layer @ top of app

there draggable circle in view

public class lockview extends view {      public lockview(context context) {         super(context);         setclickable(true);         setbackgroundcolor(0x55ff0000);         setonclicklistener(new onclicklistener() {             @override             public void onclick(view view) {                 ((viewgroup) getparent()).removeview(lockview.this);             }         });     }      @override     protected void ondraw(canvas canvas) {         super.ondraw(canvas);          shapedrawable circle=new shapedrawable(new ovalshape());         circle.setbounds(10,10,100,100);         circle.getpaint().setargb(0xff,0,0xff,0);         circle.draw(canvas);     } } 

usage:

lockview lockview = new lockview(this); windowmanager.layoutparams baseparams = new windowmanager.layoutparams(         windowmanager.layoutparams.match_parent,         windowmanager.layoutparams.match_parent,         windowmanager.layoutparams.type_phone,         windowmanager.layoutparams.flag_not_focusable,         pixelformat.translucent); addcontentview(lockview, baseparams); 

question is:

  1. how make circle draggable? cannot found method set listener circle.

  2. how align circle right bottom?


Comments