0

I have a horizontal RecyclerView and am attempting to programatically scroll by an x value.

This has so far been achieved with smoothScrollBy(x, y), however, I can't for the life of me find a solution where I can set a scroll duration, e.g. 1000ms.

Any help would me much appreciated, thanks.

The code is as follows:

private void focus() {
    View focusedRecyclerViewItem = getFocusedRecyclerViewItem();
    TextView focusedTextView = getFocusedTextView(focusedRecyclerViewItem);
    focusedTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 64);

    mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);

            mRecyclerView.clearOnScrollListeners();

            countdown();
        }
    });

    int x = (int) focusedRecyclerViewItem.getX() - mRecyclerView.getWidth() / 2;
    mRecyclerView.smoothScrollBy(x, 0);
}

To clarify as the question was not initially clear - what I am looking for is a custom duration for the smoothScrollBy() method when it is called, not a duration before the smoothScrollBy() method is called.

bitOPS
  • 31
  • 4
  • Possible duplicate of [How to animate recyclerview on scroll like Google plus/Google newsstand?](https://stackoverflow.com/questions/28181307/how-to-animate-recyclerview-on-scroll-like-google-plus-google-newsstand) – Pouya Danesh Jan 14 '19 at 08:34
  • you can use translate and customize the transactions but you haven't searched it correctly – Pouya Danesh Jan 14 '19 at 08:40
  • Please explain as this is the first Android app I'm building, I'm not too familiar with the platform. Thanks – bitOPS Jan 14 '19 at 08:42
  • take a look at this answer https://stackoverflow.com/questions/25379867/animate-recyclerview-when-scrolling hope this helps – Pouya Danesh Jan 14 '19 at 08:47
  • Sorry but I'm struggling to find a way to make it slide left/right slower from what you've linked me. Would it please be possible to provide an answer to eliminate confusion? Thanks – bitOPS Jan 14 '19 at 09:21
  • All I'm trying to do is set a duration for when it scrolls left/right. For example, if it's set to 3000 it scrolls in a direction gracefully over the course of 3000ms. `smoothScrollBy()` scrolls gracefully, just I can't modify the time it takes to do so. – bitOPS Jan 14 '19 at 09:26

0 Answers0