介绍
这篇文章给大家介绍利用android怎么实现一个左滑删除控件,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
import android.animation.ValueAnimator; import android.content.Context; import android.graphics.PointF; import android.support.v4.view.ViewConfigurationCompat; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; import android.view.ViewConfiguration; import android.view.ViewGroup; , public class  SwipeLayout extends  ViewGroup { ,public static  String TAG =,“SwipeLayout"; , ,//可以滚动的距离 ,int mSwipeWidth; , , ,PointF firstPoint; ,PointF lastPoint; , ,float mTouchSlop; , ,ValueAnimator openAnimator; ,ValueAnimator closeAnimator; , ,public SwipeLayout (Context 上下文),{ 这才能(上下文,null); ,} , ,public SwipeLayout (Context 上下文,AttributeSet attrs), { 超级才能(上下文,attrs); 时间=mTouchSlop 才能;ViewConfigurationCompat.getScaledPagingTouchSlop (ViewConfiguration.get (getContext ())); ,} , , , ,@Override ,protected void  onLayout (boolean 改变,,int l, int t, int r, int b), { int 才能;左=0; int 才能;childCount =, getChildCount (); , for 才能;(int 我=0;i1), { ,,for (int 小姐:=,1;,小姐:& lt;, childCount;, + + i), { ,,,mSwipeWidth +=, getChildAt (i) .getMeasuredWidth (); ,,} ,,} , , int 才能;widthMode =, MeasureSpec.getMode (widthMeasureSpec); int 才能;widthValue =, MeasureSpec.getSize (widthMeasureSpec); int 才能;heightMode =, MeasureSpec.getMode (heightMeasureSpec); int 才能;heightValue =, MeasureSpec.getSize (heightMeasureSpec); , switch 才能;(heightMode) { ,,case MeasureSpec.AT_MOST: ,,case MeasureSpec.UNSPECIFIED: ,,,//没有指定大小,按照第一个子控件的大小来设置 ,,,height =, mainChild.getMeasuredHeight (); ,,,休息; ,,case MeasureSpec.EXACTLY: ,,,height =, heightValue; ,,,休息; ,,} switch 才能;(widthMode) { ,,case MeasureSpec.AT_MOST: ,,case MeasureSpec.UNSPECIFIED: ,,,//没有指定大小,按照第一个子控件的大小来设置 ,,,width =, mainChild.getMeasuredWidth (); ,,,休息; ,,case MeasureSpec.EXACTLY: ,,,width =, widthValue; ,,,休息; ,,} ,//,,for (int i=1; i 利用android怎么实现一个左滑删除控件