

You can find an example of how to keep track of the recycler's scroll y here.Ĭalculating the scroll y of a given position is really dependent on what your recycler is displaying. This can be a bit tricky, since it involves keeping track of your current scroll position, and calculating the scroll position of a given y position. In this example, I use a helper method named "calculateCurrentDistanceToPosition". Return X / TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, Y, displayMetrics) Will it be possible to have smooth scroll using webview or it is a known limitation of platform views. Compare with a native webview embedded on an Android app. This code will request X milliseconds for every Y DP float calculateSpeedPerPixel(DisplayMetrics displayMetrics) Scrolling on the webview example is not smooth, also happens with animations. This code will return the amount of time it takes to scroll 1 pixel. Int yDelta = calculateCurrentDistanceToPosition(targetPosition) LinearSmoothScroller smoothScroller = new PointF computeScrollVectorForPosition(int targetPosition) A good idea would be to create this instance in some initialization method, and just set the target position in this method. Inside your layout manager, you need to implement the smoothScrollToPosition method: void smoothScrollToPosition(RecyclerView recyclerView, State state, int position) Here is the code for the activitymain.xml file. For the sake of prosperity, I will attempt to answer all of these issues now. In the activitymain.xml file add the NestedScrollView and inside NestedScrollView add a LinearLayout and inside LinearLayout add two TextView to display the strings which are created inside the strings.xml file and one Button between the TextView. Step 2 Add the following code to res/layout/activitymain.xml. Step 1 Create a new project in Android Studio, go to File New Project and fill all required details to create a new project.
Smoothscroll vs scroll android manual#
You could be referring to the automatic " smoothScrollToPosition" which will automatically scroll to a specified position, you could be talking about manual scrolling and you could be talking about flinging. This example demonstrates how do I detect scroll up and down in android listView. It's unclear what you mean when you say " smoothScroll".
