一、前言
老规矩,别的不说,这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,delta,Math.abs(delta) * 3);invalIDate();}@OverrIDepublic 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下拉刷新上拉加载更多左滑动删除所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)