- Create custom ScrollView to enable or disable scrolling Android
- Create custom ScrollView to enable or disable scrolling Android
- So how to use this custom ScrollView class ?
- for example :
- android — overscrollmode — How to disable RecyclerView scrolling?
- recyclerview disable auto scroll (16)
- Original:
- Disable auto scroll android
Create custom ScrollView to enable or disable scrolling Android
Create custom ScrollView to enable or disable scrolling Android
In android ScrollView there is no way or method to disable scrolling. but sometime if you want to disable scrolling of ScrollView while you are inside inner element, like if you want to disable ScrollView when you are inside Map view. So you can scroll Map view easily if you put Map view inside ScrollView. Because Map view has its own Scrolling feature which conflicts ScrollView’s scrolling and you are unable to scrolling map view. So at that time you think to disable Scrolling of ScrollView when you touch or make focus on Map view. But when you try to implement this then you get to know that there is no method to disable scrolling of ScrollView. You can disable the whole ScrollView but that is not a correct way to do this. So we can make our own ScrollView which having extra features are enable Scrolling or Disable scrolling. and we can do this using Inheritance feature of OOPS. So we will create a class which will Extend ScrollView class, which means our class will have all features derive from Base (ScrollView) class. ok so lets do this :
- create a new class and name it what you want, i will name it as MyScrollView. and extend ScrollView class.
- Now you need to create constructor of your class, Android studio will give you 4 type of Constructor. extend all of them. because in future we can use that constructors.
- override 2 methods of ScrollView “onInterceptTouchEvent” and “onTouchEvent”.
- create a boolean variable which will check that scrolling is enabled or disabled. by default set its value to true.
- now create boolean type method and return that variable which you have just created.
- Now create a void method to enable and disable scrolling which requires a parameter of boolean type. i will name this method as setScrolling(boolean enable) as shown below :
So how to use this custom ScrollView class ?
- Goto your xml file where you want to use ScrollView. if you already have ScrollView inside your xml then replace that ScrollView tag with your custom ScrollView’s class name and package name.
for example :
change this to (i will use my package name and Class name, change accoring to yours) :
Ok so now you have embedded your own ScrollView. to disable scrolling just call setScrolling() method to object of your ScrollView and pass value (true or false) where you want to disable. as shown in below example :
Источник
android — overscrollmode — How to disable RecyclerView scrolling?
recyclerview disable auto scroll (16)
I cannot disable scrolling in the RecyclerView . I tried calling rv.setEnabled(false) but I can still scroll.
How can I disable scrolling?
in your child of SrollView or NestedScrollView (and parent of ListView, recyclerview and gridview any one)
Another alternative is setLayoutFrozen , but it comes with a bunch of other side effects.
Create class which extend RecyclerView class
This will disable the scroll event, but not the click events
Use this in your XML do the following:
Extend the LayoutManager and override canScrollHorizontally() and canScrollVertically() to disable scrolling.
Be aware that inserting items at the beginning will not automatically scroll back to the beginning, to get around this do something like:
Here is how I did it with data binding:
In place of the «true» I used a boolean variable that changed based on a condition so that the recycler view would switch between being disabled and enabled.
I have been struggling in this issue for some hour, So I would like to share my experience, For the layoutManager solution it is fine but if u want to reEnable scrolling the recycler will back to top.
The best solution so far (for me at least) is using @Zsolt Safrany methode but adding getter and setter so you don’t have to remove or add the OnItemTouchListener.
If you just disable only scroll functionality of RecyclerView then you can use setLayoutFrozen(true); method of RecyclerView . But it can not be disable touch event.
Just add this to your recycleview in xml
The REAL REAL answer is: For API 21 and higher:
No java code needed. You can set android:nestedScrollingEnabled=»false» in xml:
The real answer is
There is a realy simple answer.
The above code disables RecyclerView vertically scrolling.
This a bit hackish workaround but it works; you can enable/disable scrolling in the RecyclerView .
This is an empty RecyclerView.OnItemTouchListener stealing every touch event thus disabling the target RecyclerView .
Wrote a kotlin version:
You can add this line after setting your adapter
Now your recyclerview will work with smooth scrolling
You should override the layoutmanager of your recycleview for this. This way it will only disable scrolling, none of ther other functionalities. You will still be able to handle click or any other touch events. For example:-
Original:
Here using «isScrollEnabled» flag you can enable/disable scrolling functionality of your recycle-view temporarily.
Simple override your existing implementation to disable scrolling and allow clicking.
in XML :-
in the child RecyclerView layout XML file
in Java :-
to your RecyclerView in Java code.
Using ViewCompat (Java) :-
Источник
Disable auto scroll android
Androidx Auto Scroll ViewPager
- ViewPager which can auto scrolling, cycling, decelerating.
- ViewPager which can be slided manually in parent ViewPager.
- ViewPager which is compatible with AndroidX library.
- ViewPager which is written in Kotlin and be supported for a long time.
Many thanks to Trinea because this library is the newest, kotlin version of his library. We support AndroidX library, so if you have problem when migrating to AndroidX, this version should work like a charm.
Add this to your root build.gradle file under repositories:
Add this to your app level build.gradle as dependency:
Latest version:
Источник