Android dropdown Refresh Pull-up load more, high imitation iOS left swipe to delete item, solve many gesture problems

Source: Internet
Author: User

First, preface

The usual, other do not say, this demo is to find a very relevant knowledge set, can say to me this small white is racking my brains! The programmer is talking about no picture, no truth! Now let's get a glimpse of it!



Second, the more critical or scroller this class of

Package Com.icq.slideview.view;import Android.content.context;import Android.util.attributeset;import Android.util.log;import Android.util.typedvalue;import Android.view.motionevent;import Android.view.View;import Android.widget.linearlayout;import Android.widget.relativelayout;import Android.widget.scroller;import Android.widget.textview;import Com.icq.slideview.r;public class Slideview extends LinearLayout {private static final S    Tring TAG = "Slideview";    Private Context Mcontext;    Private LinearLayout mviewcontent;    Private Relativelayout Mholder;    Private Scroller Mscroller;    Private Onslidelistener Monslidelistener;    private int mholderwidth = 120;    private int mlastx = 0;    private int mlasty = 0;    private static final int TAN = 2;        Public interface Onslidelistener {public static final int slide_status_off = 0;        public static final int slide_status_start_scroll = 1;        public static final int slide_status_on = 2; /** * @param View current Slideview * @param status slide_status_on or Slide_status_off */public void Onslide (    View view, int status);        } public Slideview (context context) {super (context);    Initview ();        } public Slideview (context context, AttributeSet Attrs) {Super (context, attrs);    Initview ();        } private void Initview () {mcontext = GetContext ();        Mscroller = new Scroller (mcontext);        SetOrientation (linearlayout.horizontal);        View.inflate (Mcontext, R.layout.slide_view_merge, this);        Mviewcontent = (linearlayout) Findviewbyid (r.id.view_content); Mholderwidth = Math.Round (Typedvalue.applydimension (Typedvalue.complex_unit_dip, Mholderwidth, GetResource    S (). Getdisplaymetrics ()));    public void SetButtonText (charsequence text) {((TextView) Findviewbyid (R.id.delete)). SetText (text); } public void Setcontentview (view view) {MVIEWCONTENT.ADdview (view);    } public void Setonslidelistener (Onslidelistener onslidelistener) {monslidelistener = Onslidelistener;        } public void Shrink () {if (GETSCROLLX ()! = 0) {this.smoothscrollto (0, 0);        }} public void Onrequiretouchevent (Motionevent event) {int x = (int) event.getx ();        int y = (int) event.gety ();        int scrollx = GETSCROLLX ();        LOG.D (TAG, "x=" + x + "y=" + y);         Switch (event.getaction ()) {case Motionevent.action_down: {int deltax = X-MLASTX;            System.out.println ("Press the offset" +deltax);            if (!mscroller.isfinished ()) {mscroller.abortanimation (); } if (Monslidelistener! = null) {Monslidelistener.onslide (this, Onslidel Istener.            Slide_status_start_scroll);        } break;            } case motionevent.action_move: {int deltax = X-MLASTX; int DeltaY =Y-mlasty;            System.out.println ("offset" +deltax);            if (Math.Abs (DeltaX) < Math.Abs (deltay) * TAN) {break;            } int newscrollx = Scrollx-deltax;                if (deltax! = 0) {if (Newscrollx < 0) {newscrollx = 0;                } else if (Newscrollx > Mholderwidth) {newscrollx = Mholderwidth;            } this.scrollto (NEWSCROLLX, 0);        } break;            } case MOTIONEVENT.ACTION_UP: {int newscrollx = 0;            if (scrollx-mholderwidth * 0.75 > 0) {newscrollx = Mholderwidth;            } this.smoothscrollto (NEWSCROLLX, 0); if (Monslidelistener! = null) {Monslidelistener.onslide (this, newscrollx = = 0?)            OnSlideListener.SLIDE_STATUS_OFF:OnSlideListener.SLIDE_STATUS_ON);    } break;    } Default:break;        } MLASTX = x;    Mlasty = y;        } private void Smoothscrollto (int destx, int desty) {//Slow scroll to the specified position int scrollx = GETSCROLLX ();        int delta = DESTX-SCROLLX;        System.out.println ("offset scrollx" +scrollx);        SYSTEM.OUT.PRINTLN ("Deviation delta" +delta);        int a= Math.Abs (delta) * 3;        System.out.println ("What do You Mean" +a);        Mscroller.startscroll (SCROLLX, 0, Delta, 0, Math.Abs (Delta) * 3);    Invalidate (); } @Override public void Computescroll () {if (Mscroller.computescrolloffset ()) {System.out.println ("when        Top x Position: "+mscroller.getcurrx ());            System.out.println ("Current y position:" +mscroller.getcurry ());            ScrollTo (Mscroller.getcurrx (), Mscroller.getcurry ());        Postinvalidate (); }    }}

Third, the direct source download: (Will be made up (qq:508181017))

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.