public class SlideRightViewDragHelper extends LinearLayout {
private ViewDragHelper viewDragHelper;
private View child;
private Point childPosition = new Point();
private Point childEndPosition = new Point();
private OnReleasedListener onReleasedListener;
private int oldX;
private int screenWidth;//屏幕宽
private int screenWidthto = 70;//当前滑动比例 大于这个值时滑动完成、小于时回弹
public SlideRightViewDragHelper(Context context, AttributeSet attrs) {
super(context, attrs);
screenWidth = getResources().getDisplayMetrics().widthPixels;//获取屏幕宽
//新建viewDragHelper ,viewGroup, 灵敏度,回调(子view的移动)
viewDragHelper = ViewDragHelper.create(this, 1.0f, new ViewDragHelper.Callback() {
@Override
public boolean tryCaptureView(View child, int pointerId) {
return true;
}
@Override
public int clampViewPositionHorizontal(View child, int left, int dx) {
oldX = left;
return Math.max(0, left);
}
@Override
public void onViewReleased(View releasedChild, float xvel, float yvel) {
//滑动比例大于70,视为滑动完成
if ((oldX*100/screenWidth) > screenWidthto) {
viewDragHelper.settleCapturedViewAt(childPosition.x, childPosition.y); //不管是滑动成功还是失败,都必须反弹
android仿滴滴司机端滑动接到乘客,送达乘客的滑动Button
最新推荐文章于 2024-10-02 13:42:03 发布
这篇博客展示了如何在Android中创建一个仿滴滴司机端的滑动Button,实现接到乘客和送达乘客的效果。通过使用CardView实现圆角裁剪,并介绍了滑动完成的回调方法实现,可以根据项目需求选择是否使用CardView。
摘要由CSDN通过智能技术生成