Android pull down refresh pull load more left slide Delete _android

Source: Internet
Author: User
Tags abs

First, the preface

The old rules, others do not say, this demo is to find a very relevant knowledge of the collection, can be said to me this small white is racked my brains! Programmers are talking about no picture, no truth!

Now, everybody, come on!

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 String TAG = Slideview; private context Mcontext; Priva
Te 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_star
T_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); Slideview (context) {super (context); Initview ();} public Slideview (context, AttributeSet attrs)
{Super (context, attrs); Initview ();} private void Initview () {mcontext = GetContext (); mscroller = new Scroller (mcontext); SetOrientation (Linearlayout.horizo
Ntal);
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, GetResources ().
Getdisplaymetrics ())); public void SetButtonText (charsequence text) {(TextView) Findviewbyid (R.id.delete)). SetText (text); Setcontentview (view view) {Mviewcontent.addview (view);} public void Setonslidelistener (Onslidelistener Onslidelistener) {Monslidelistener = onslidelistener} public void shrink () {if (GETSCROLLX ()!= 0) {This.smoothscroll
to (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, onslidelistener.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 = Mholde
Rwidth;
} 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 scrolling to the specified position int scrollx = GETSCROLLX (); int delta = DESTX-SCROLLX
;
System.out.println (offset scrollx+scrollx);
System.out.println (offset difference delta+delta);
int a= Math.Abs (delta) * 3;
System.out.println (what meaning +a);
Mscroller.startscroll (SCROLLX, 0, Delta, 0, Math.Abs (Delta) * 3);
Invalidate (); @Override public void Computescroll () {if (Mscroller.computescrolloffset ()) {System.out.println () (current x position: +
Mscroller.getcurrx ());
System.out.println (current y position: +mscroller.getcurry ());
Scrollto (Mscroller.getcurrx (), Mscroller.getcurry ());
Postinvalidate (); }
}
}

Related Article

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.