我是靠谱客的博主 洁净小兔子,这篇文章主要介绍AndroidSwipeLayout 分析,现在分享给大家,希望可以做个参考。

https://github.com/daimajia/AndroidSwipeLayout

侧滑的删除按钮在右边为例分析:



核心函数:

复制代码
1
ViewDragHelper //拉动效果的函数。


打开app,初始化view

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?xml version="1.0" encoding="utf-8"?> <com.daimajia.swipe.SwipeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/godfather" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:layout_gravity="right" android:src="@drawable/bird" android:layout_width="100dp" android:layout_height="100dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="nihao"/> </com.daimajia.swipe.SwipeLayout>

1. addView  ImageView

2. addView TextView

3. 调了两次onLayout

复制代码
1
protected void onLayout(boolean changed, int l, int t, int r, int b) {
07-20 19:30:37.926 25279-25279/com.daimajia.swipedemo D/SwipeLayout: onLayout() called with: changed = [true], l = [0], t = [0], r = [480], b = [672]
07-20 19:30:37.976 25279-25279/com.daimajia.swipedemo D/SwipeLayout: onLayout() called with: changed = [false], l = [0], t = [0], r = [480], b = [672]



复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
void layoutPullOut() { // 如果两个view,拼成一个view的。 View surfaceView = getSurfaceView(); // TextView Log.d(TAG, "layoutPullOut: surfaceView:"+surfaceView); Rect surfaceRect = mViewBoundCache.get(surfaceView); if(surfaceRect == null) surfaceRect = computeSurfaceLayoutArea(false); //Rect(0, 0 - 480, 672) 左上(0,0)右下(480,672) if (surfaceView != null) { surfaceView.layout(surfaceRect.left, surfaceRect.top, surfaceRect.right, surfaceRect.bottom); bringChildToFront(surfaceView); } View currentBottomView = getCurrentBottomView();//imageview Rect bottomViewRect = mViewBoundCache.get(currentBottomView); if(bottomViewRect == null) bottomViewRect = computeBottomLayoutAreaViaSurface(ShowMode.PullOut, surfaceRect);//Rect(480, 0 - 630, 672) if (currentBottomView != null) { currentBottomView.layout(bottomViewRect.left, bottomViewRect.top, bottomViewRect.right, bottomViewRect.bottom); } }




layoutPullout效果就是这样的。




1.

复制代码
1
onTouchEvent ACTION_DOWN

按第一下,全局变量记录这个点。

2.滑动:

复制代码
1
MotionEvent.ACTION_MOVE
  1.判断滑动方向

  2.

复制代码
1
2
mDragHelper.processTouchEvent(ev);

复制代码
1
clampViewPositionHorizontal
复制代码
1
2
3
4
5
6
7
8
9
case Right: if (left > getPaddingLeft()) return getPaddingLeft(); if (left < getPaddingLeft() - mDragDistance) return getPaddingLeft() - mDragDistance; break return left;

复制代码
1

复制代码
1




最后

以上就是洁净小兔子最近收集整理的关于AndroidSwipeLayout 分析的全部内容,更多相关AndroidSwipeLayout内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(78)

评论列表共有 0 条评论

立即
投稿
返回
顶部