RecyclerViewPager


Source link: https://github.com/lsjwzh/RecyclerViewPager

RecyclerViewPager

A ViewPager implemention base on RecyclerView. Support fling operation like gallary.

android.support.v4.view.ViewPager??????

Features:

  1. Base on RecyclerView.
  2. Custom fling factor.
  3. Custom paging trigger.
  4. Support Vertical and Horizontal orientation.
  5. Support FragmentViewPager (api 12+)
  6. Infinite-Loop-ViewPager
  7. Support TabLayout

??:

  1. ???RecyclerView.
  2. ????fling????.
  3. ??????????.
  4. ????ViewPager.
  5. ??Fragment (api 12+)
  6. ??????
  7. ???TabLayout????

Usage

how to import?

add this into gradle

// Yes, I have switched to jitpack.io.  repositories {

  ...
  maven {
 url "https://jitpack.io" 
}

  ... 
}
  dependencies {

  ...
  compile 'com.github.lsjwzh.RecyclerViewPager:lib:v1.1.2@aar'
  ... 
}

add proguard rules if need

-keep class com.lsjwzh.widget.recyclerviewpager.** -dontwarn com.lsjwzh.widget.recyclerviewpager.** 

Basic Usage:

It is easy to setup like a Recycler List View.

xml:

<com.lsjwzh.widget.recyclerviewpager.RecyclerViewPager
  android:id="@+id/list"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingLeft="15dp"
  android:paddingRight="15dp"
  app:rvp_triggerOffset="0.1"
  app:rvp_singlePageFling="true"
  android:clipToPadding="false"/>

code:

RecyclerViewPager mRecyclerView = (RecyclerViewPager) view.findViewById(R.id.list);
  // setLayoutManager like normal RecyclerView, you do not need to change any thing. LinearLayoutManager layout = new LinearLayoutManager(getActivity(),LinearLayoutManager.HORIZONTAL,false);
 mRecyclerView.setLayoutManager(layout);
  //set adapter //You just need to implement ViewPageAdapter by yourself like a normal RecyclerView.Adpater. mRecyclerView.setAdapter(new RecyclerView.Adpater<X>());
  // That is all. 

Support TabLayout:

1.Add Dependency:

dependencies {

  ...
  compile 'com.github.lsjwzh.RecyclerViewPager:tablayoutsupport:v1.1.2@aar'
  ... 
}

2.Call 'setupWithViewPager'

TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
 TabLayoutSupport.setupWithViewPager(tabLayout, mRecyclerView, mAdapter);

Infinite Loop ViewPager:

<com.lsjwzh.widget.recyclerviewpager.LoopRecyclerViewPager

android:id="@+id/viewpager"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_marginTop="20dp"

android:clipToPadding="false"

android:paddingTop="15dp"

android:paddingBottom="15dp"/>

You just need to use LoopRecyclerViewPager replace RecyclerViewPager. The usage of LoopRecyclerViewPager is the same as RecyclerViewPager. No matter what you specify position you want to scroll, LoopRecyclerViewPager will transform it to right position. Ex:In a LoopRecyclerViewPager with 10 items, scrollToPosition(1) will get same scroll behavior as scrollToPosition(11)? scrollToPosition(21) and so on.

How to get actual position in LoopRecyclerViewPager:


 int actualPosition = mLoopRecyclerViewPager.transformToActualPosition(adapterPosition);
 

If you just want to get current actual position, you can do it like this:


 int actualCurrentPosition = mLoopRecyclerViewPager.getActualCurrentPosition();
 

Release Notes:

1.1.2 merge some fix. 1.1.1 merge some fix. 1.1.0stable fix bug:LoopViewPager position confusion;LoopViewPager non stop spinning; 1.1.0beta5 feat: TabLayoutSupport Lib supports LoopViewPager 1.1.0beta4 fix bug:support ItemDecorations; 1.1.0beta3 support reverse; 1.1.0 refactor;support TabLayout; 1.0.11 support infinite loop 1.0.10 make touch gesture smother? 1.0.8 override swapAdapter?support singlePageFling? 1.0.7 remove redandunt codes; support cancel action 1.0.6 resolve potential id conflicting on FragmentViewPagerApdater 1.0.4 fix bug : exception happens if  ItemView LayoutParam is not MarginLayoutParam 1.0.3 add method: getCurrentPosition 1.0.2 support FragmentViewPager, add OnPageChangedListener 1.0.1 fix bug: smoothScrollToPosition index out of range 1.0.0 reimplement RecyclerViewPager without coping RecyclerView's codes.  0.5.4 add 'HorizontalCenterLayoutManager' to implement ViewPager 0.5.3 fix bug: setHasStableIds not work 0.1.0 

Special Thanks:

saadfarooq taxomania

ToDo:

Vertical ViewPager FragmentViewPager observe OnPageChanged Infinite-Loop-ViewPager ~~Support TabLayout ~~ Support ViewPagerIndicator Wrap Content? dispatchTouchEvent override demo

License

Copyright 2015 lsjwzh  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. 

Resources

Cute library to implement SearchView in a Material Design Approach.

Lightweight HTTP client for Android.

Android button which can morph from one shape to another.

Android Test Automation.

Android library for Wearable Internet of Things class at URI. It provides wrappers to Google Play Services, and base classes for simple development.

AndroidChannel is helper library for inter thread communication between main thread and worker thread. AndroidChannel uses HandlerThread for inter thread communication.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes