PeekAndPop 一个模仿iOS中3D Touch效果的库
万年老5
9年前
PeekAndPop是一个开源的Android 库,模仿iOS中3D Touch效果的库。因为安卓本身不支持3D Touch,所以事件的触发是用长按点击来替代。
Peek and pop allows you to long click on a view to "peek" and see a larger view in the centre of the screen. The pop feature can be imitated using fling to action gestures or from a hold and release event.
特性:
- Create a basic peek and pop that shows on long click and is dismissed on touch up.
- Fling to action, where flinging the view upwards or downwards (sidewards in landscape) triggers an event.
- Specify views within the peek view layout that can listen to long hold events (if the user holds the view for a certain amount of time).
- Specify views within the peek view layout that can listen to hold and release events (where the user holds the view and then releases).
使用说明:
开始
这个库托管在 Jitpack.io,所以在根 build.gradle文件中添加:
allprojects { repositories { ... maven { url "https://jitpack.io" } } }
然后在application的 build.gradle文件中添加如下依赖:
dependencies { compile 'com.github.shalskar:PeekAndPop:v0.1.1' }
基本的使用很简单,只需一个activity实例,一个为 peek and pop准备的布局文件,一个或者多个在长按之后显示的 peek and pop视图。
PeekAndPop peekAndPop = new PeekAndPop.Builder(this) .peekLayout(R.layout.peek_view) .longClickViews(view) .build();
你可以调用PeekAndPop对象的getPeekView()来得到 peek view ,并使用 findViewById() 来得到 peek layout中的任意视图。
View peekView = peekAndPop.getPeekView(); ImageView imageView = peekView.findViewById(R.id.image_view); TextView textView = peekView.findViewById(R.id.text_view);
通常你可能还会想在列表中的某个item被点击时显示peek and pop ,为了让peek and pop正常工作,你需要添加这行代码:
.parentViewGroupToDisallowTouchEvents(viewGroup)