Created
May 1, 2019 17:58
-
-
Save dinorahto/b91971e5073b1e90da3a0bbe02e4bbf0 to your computer and use it in GitHub Desktop.
ViewPager adapter for not drag event
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Created by Dinorah Tovar on 12/20/17. | |
| * ViewPager | |
| */ | |
| public class CustomViewPager extends ViewPager { | |
| public CustomViewPager(Context context) { | |
| super(context); | |
| setMyScroller(); | |
| } | |
| public CustomViewPager(Context context, AttributeSet attrs) { | |
| super(context, attrs); | |
| setMyScroller(); | |
| } | |
| @Override | |
| public boolean onInterceptTouchEvent(MotionEvent event) { | |
| return false; | |
| } | |
| @Override | |
| public boolean onTouchEvent(MotionEvent event) { | |
| return false; | |
| } | |
| private void setMyScroller() { | |
| try { | |
| Class<?> viewpager = ViewPager.class; | |
| Field scroller = viewpager.getDeclaredField("mScroller"); | |
| scroller.setAccessible(true); | |
| scroller.set(this, new MyScroller(getContext())); | |
| } catch (Exception e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| public class MyScroller extends Scroller { | |
| public MyScroller(Context context) { | |
| super(context, new DecelerateInterpolator()); | |
| } | |
| @Override | |
| public void startScroll(int startX, int startY, int dx, int dy, int duration) { | |
| super.startScroll(startX, startY, dx, dy, 350); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <your.packager.CustomViewPager | |
| android:id="@+id/viewpager" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" | |
| app:layout_behavior="@string/appbar_scrolling_view_behavior" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment