Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/ditclear/TimeLine

本是一个时间轴的demo,现在成为了一个简易的侧滑菜单控件,提供了仿IOS的越界回弹效果和左右滑动功能,可自由设置最小滑动距离和是否开启滑动功能
https://github.com/ditclear/TimeLine

swipelayout timeline

Last synced: 1 day ago
JSON representation

本是一个时间轴的demo,现在成为了一个简易的侧滑菜单控件,提供了仿IOS的越界回弹效果和左右滑动功能,可自由设置最小滑动距离和是否开启滑动功能

Lists

README

        

# TimeLine

![](https://img.shields.io/badge/minSdk-17-brightgreen.svg) ![](https://img.shields.io/badge/version-1.1.0-green.svg) ![](https://img.shields.io/badge/star-375-blue.svg) ![](https://img.shields.io/badge/fork-91-blue.svg)
> 提供了仿IOS的越界回弹效果和左右滑动功能,可自由设置最小滑动距离和是否开启滑动功能

示例:[demo.apk](apk/timeline.apk)

#### Download
implementation 'com.ditclear:swipedraglayout:1.1.0'

#### 截图

![](screenshot/feature.gif) ![](screenshot/modify.gif)

![](screenshot/recyclerview.gif) ![](screenshot/listview.gif)

### Feature

- [SwipeDragLayout](https://github.com/vienan/TimeLine/blob/master/swipelayout/src/main/java/com/ditclear/swipelayout/SwipeDragLayout.java)使用ViewDragHelper来进行滑动操作,代码少,易理解,核心代码不过150行
- 使用了保留一个静态类的方法来确保只有一个展开,并在`onDetachedFromWindow`方法中进行关闭操作
- 提供了多种自定义属性,见下表
- [sample](https://github.com/ditclear/SwipeLayout/blob/8d5cfdce76249150b3c37c72cd0a600138fe00d8/app/src/main/java/vienan/app/expandableswipelistview/RecyclerActivity.java)使用了DataBinding和kotlin 进行了多类型的绑定,对于了解和使用DataBinding大有益处,添加多种Type更是十分简单,再也不用extends RecyclerView.Adapter了,可以参考[BindingListAdapter](https://github.com/ditclear/BindingListAdapter)

#### 自定义属性

| attr | type | default | meaning |
| --------------- | :-----: | ------: | :-----------------------: |
| need_offset | float | 0.2f | 最小需要滑动的比例 |
| ios | boolean | true | 拖动越界回弹效果 |
| swipe_enable | boolean | true | 开启滑动 |
| swipe_direction | enum | left | 滑动方向,默认1是左滑left,2为右滑right |

#### 示例

```xml





```

> 注意

暂时只支持两个子View,一个content,一个侧滑的menu,以后会支持

#### 回调监听

```java
public interface SwipeListener {

/**
* 拖动中,可根据offset 进行其他动画
* @param layout
* @param offsetRatio 偏移相对于menu宽度的比例
* @param offset 偏移量px
*/
void onUpdate(SwipeDragLayout layout, float offsetRatio, float offset);

/**
* 展开完成
* @param layout
*/
void onOpened(SwipeDragLayout layout);

/**
* 关闭完成
* @param layout
*/
void onClosed(SwipeDragLayout layout);
}
```

### License

```txt
Copyright 2018 ditclear

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```