Android下拉刷新上拉加载更多左滑动删除
程序员文章站
2023-12-19 12:54:52
一、前言
老规矩,别的不说,这demo是找了很相关知识集合而成的,可以说对我这种小白来说是绞尽脑汁!程序员讲的是无图无真相!
现在大家一睹为快!
二、比较...
一、前言
老规矩,别的不说,这demo是找了很相关知识集合而成的,可以说对我这种小白来说是绞尽脑汁!程序员讲的是无图无真相!
现在大家一睹为快!
二、比较关键的还是scroller这个类的
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; 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, getresources() .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(按下偏移+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(偏移+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) { // 缓慢滚动到指定位置 int scrollx = getscrollx(); int delta = destx - scrollx; system.out.println(偏移scrollx+scrollx); system.out.println(偏移差delta+delta); int a= math.abs(delta) * 3; system.out.println(什么意思+a); mscroller.startscroll(scrollx, 0, delta, 0, math.abs(delta) * 3); invalidate(); } @override public void computescroll() { if (mscroller.computescrolloffset()) { system.out.println(当前x位置:+mscroller.getcurrx()); system.out.println(当前y位置:+mscroller.getcurry()); scrollto(mscroller.getcurrx(), mscroller.getcurry()); postinvalidate(); } } }
推荐阅读
-
Android下拉刷新上拉加载更多左滑动删除
-
Android RecyclerView上拉加载和下拉刷新
-
Android RecyclerView上拉加载和下拉刷新(基础版)
-
Android RecyclerView实现下拉刷新和上拉加载更多
-
Android使用ListView实现下拉刷新及上拉显示更多的方法
-
android RecyclerView侧滑菜单,滑动删除,长按拖拽,下拉刷新上拉加载
-
Android控件PullRefreshViewGroup实现下拉刷新和上拉加载
-
Android使用ListView实现下拉刷新及上拉显示更多的方法
-
android RecyclerView侧滑菜单,滑动删除,长按拖拽,下拉刷新上拉加载
-
Android控件PullRefreshViewGroup实现下拉刷新和上拉加载