If you simulate the effect of a color gradient when an icon is deleted, use transitiondrawable.

Source: Internet
Author: User

:


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.