:
Transitiondrawable can be used to achieve the transition effect of two drawable directly staggered gradient
Next, let's do this:
Public class mydraglayer extends framelayout {/*** the bitmap that is currently being dragged */private bitmap mdragbitmap = NULL; private float mlastmotionx; private float mlastmotiony; private float moffsetx; private float moffsety; Private Static final int transition_duration = 250; public view mtrashbin; public view mdroptarget; private final paint mtrashpaint = new paint (); Private paint mdragpaint; PR Ivate transitiondrawable mtransition; Public mydraglayer (context, attributeset attrs, int defstyle) {super (context, attrs, defstyle);} public mydraglayer (context, attributeset attrs) {super (context, attrs);} public mydraglayer (context) {super (context) ;}@ override public Boolean onintercepttouchevent (motionevent eV) {mlastmotionx = eV. getx (); mlastmotiony = eV. gety (); int DX = 0; int DY = 0; If (mdragbitmap! = NULL) {dx = (INT) (mlastmotionx-moffsetx + mdragbitmap. getwidth ()/2); DY = (INT) (mlastmotiony-moffsety + mdragbitmap. getheight ()/2);} int action = eV. getaction (); If (Action = motionevent. action_move) {// if you enter the trash view range, mdroptarget must be trashbin Boolean preistrash = mdroptarget = mtrashbin; mdroptarget = finddroptarget (dx, Dy ); boolean currentistrash = mdroptarget = mtrashbin; If (! Preistrash & currentistrash) {// mtransition. reversetransition (transition_duration);} else if (preistrash &&! Currentistrash) {// There is a garbage bin outside the mtransition. reversetransition (transition_duration);} If (currentistrash) {mdragpaint = mtrashpaint;} else {mdragpaint = NULL;} else if (Action = motionevent. action_up) {mdroptarget = finddroptarget (dx, Dy); If (mdroptarget = mtrashbin) {invalidate (); Return true; // quicknavgridview will receive action_cancel} invalidate (); boolean result = super. onintercept Touchevent (EV); return result;} private view finddroptarget (int x, int y) {If (mtrashbin! = NULL & mtrashbin. getvisibility () = view. visible) {rect r = new rect (); // map the coordinates of mtrashbin to mtrashbin on rect R. gethitrect (r); If (R. contains (x, y) {return mtrashbin ;}} return NULL ;}@ overrideprotected void dispatchdraw (canvas) {super. dispatchdraw (canvas); If (mdragbitmap! = NULL &&! Mdragbitmap. isrecycled () {// draw actual icon being draggedcanvas. drawbitmap (mdragbitmap, getscrollx () + response-moffsetx, getscrolly () + response-moffsety, mdragpaint);} public void startdrag (Bitmap bitmap, int offsetx, int offsety) {mdragbitmap = bitmap; moffsetx = offsetx; moffsety = offsety; mdragpaint = NULL; invalidate ();} public void settrashbin (view) {mtrashbin = view; mtransition = (callback) view. getbackground ();}}
Activity:
@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.test);MyLinearlayout layout = (MyLinearlayout)findViewById(R.id.linear);layout.mDragLayer = (MyDragLayer) findViewById(R.id.rootView);layout.mDragLayer.setTrashBin(findViewById(R.id.trashbin));}
Code: http://download.csdn.net/detail/baidu_nod/7759965