PeekAndPop 一個模仿iOS中3D Touch效果的庫
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)
本文由用戶 萬年老5 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!