I have ViewPager and below it I have 10 buttons. By clicking on button, for example #4, the pager goes immediately to page #4 by mPager.setCurrentItem(3);
. But, I want to disable the paging by swiping with finger horizontally. Thus, the paging is done ONLY by clicking on the buttons.
So, how I can disable the swiping with finger?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
I wrote a
CustomViewPager
with a swiping control:If you set
canScroll
totrue
, thisViewPager
can be swiping with finger,false
on the contrary.I use this in my project, and it works great until now.
Better to declare it styleable, so you can change its property from xml:
And in your values/attr.xml:
so that you can use it in you layout xml:
Of course, you can still have a get/set property.
I know it's mighty late to post this but here's a tiny hack to achieve your outcome ;)
Simply add a dummy view below your viewpager:
Then add a
OnClickListener
to yourRelativeLayout
.Get a bit creative with layouts, their placements and their behaviour and you'll learn to find a way to do absolutely anything that you imagine :)
Good luck!
If you want to implement the same for Android in Xamarin, here is a translation to C#
I chose to name the attribute "ScrollEnabled". Because iOS just uses the excat same naming. So, you have equal naming across both platforms, makes it easier for developers.
In .axml file:
The simplest way is to
setOnTouchListener
and returntrue
forViewPager
.The more general extension of
ViewPager
would be to create aSetPagingEnabled
method so that we can enable and disable paging on the fly. To enable / disable the swiping, just overide two methods:onTouchEvent
andonInterceptTouchEvent
. Both will return "false" if the paging was disabled.Then select this instead of the built-in viewpager in XML
You just need to call the
setPagingEnabled
method withfalse
and users won't be able to swipe to paginate.