RandomDragLayout
简介:任意拖布局 (扩展自 QQ 空间的列表 Header 效果)
标签:
博客详情: https://blog.csdn.net/u011387817/article/details/84136291
使用方式:
添加依赖:
implementation 'com.wuyr:randomdraglayout:1.2.0'
APIs:
Method | Description |
---|---|
boolean reset() | 重置状态 (重新初始化) |
setChildRefreshPeriod(long period) | 设置子 View 的重绘间隔时长 默认:0 (不重绘) 一般是内容会不断更新的 View 才需要设置此参数, 静态的 View 无需设置 |
setAlphaAnimationDuration(long duration) | 设置透明渐变动画时长 默认: 200L |
setFlingDuration(long duration) | 设置位移动画时长 默认: 800L |
setScrollAvailabilityRatio(float ratio) | 设置惯性移动的利用率 范围: 0~1 默认: 0.8F |
setOnDragListener(OnDragListener onDragListener) | 监听拖动 参数: 绝对 X, 绝对 Y, 绝对旋转角度 |
setOnStateChangeListener(OnStateChangeListener listener) | 监听状态变化 状态: STATE_NORMAL (普通状态) STATE_DRAGGING (正在拖拽中) STATE_FLINGING (惯性移动中(有滑动速率)) STATE_FLEEING (手指松开后,动画移动中(无速率)) STATE_OUT_OF_SCREEN (已经移动到屏幕外面) STATE_GONE (在屏幕内慢慢消失掉(透明渐变)) |
int getState() | 获取当前状态 状态: 见上 |
int getTargetOrientation() | 获取当前位移动画前进的方向 方向: ORIENTATION_LEFT (向左移动) ORIENTATION_RIGHT (向右移动) ORIENTATION_TOP (向上移动) ORIENTATION_BOTTOM (向下移动) |
RectF getBounds() | 获取映射后的 Bitmap 边界 (即:包括了旋转之后的宽高) |
使用示例:
在目标 View 外面直接套一层 RandomDragLayout: (可以作用到任意 View 上)
<com.wuyr.randomdraglayout.RandomDragLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#88F"
android:padding="16dp"
android:text="RandomDragLayoutTest" />
</com.wuyr.randomdraglayout.RandomDragLayout>
宽高可直接使用 wrap_content,RandomDragLayout 会根据里面的 View 调整自身大小。
OK,现在已经可以正常运行了,还可以在代码里面去设置一些属性或者监听各种状态。
Demo 下载: app-debug.apk
库源码地址: https://github.com/Ifxcyr/RandomDragLayout
效果图 (图 1: QQ 空间效果):