2

the scrollbar in my RecyclerView doesn't work, I mean I can scroll the RecyclerView with touch, I also can see the scrollbar but it's can not move

Before ask the question I also tried with some answers here for example: https://www.dev2qa.com/android-recyclerview-horizontal-scroll-example/

Android RecyclerView Scroll not working after Layout edit

But none of them work for me

Below is my code, thanks in advance

Layout file:

     <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".HexViewActivity">

       <android.support.v7.widget.RecyclerView
            android:id="@+id/rv_hex"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fadeScrollbars="false"

            android:scrollbarSize="15dp"
            android:scrollbars="vertical" />

</ScrollView>

Code to create the view

RecyclerView recyclerView = findViewById(R.id.rv_hex);
recyclerView.setLayoutManager(new LinearLayoutManager(HexConstant.app_ontext));
m_fileDataAdapter = new FileDataAdapter(HexConstant.app_ontext, files[0]);
                                        recyclerView.setAdapter(m_fileDataAdapter);
recyclerView.setNestedScrollingEnabled(true);

Is there any example for Scrollbar + recyclerView, pls let me know

Gerry
  • 86
  • 2
  • 13
  • Can you provide the full code? Why are you wrapping your `RecyclerView` in a `LinearLayout`? And did you set your adapter on the recycler view. Try changing the code to `RecyclerView recyclerView = findViewById(R.id.rv_hex); recyclerView.setLayoutManager(new LinearLayoutManager(this)); m_fileDataAdapter = new FileDataAdapter(this, files[0]); recyclerView.setAdapter(m_fileDataAdapter); recyclerVIew.setAdapter(m_fileDataAdapter);` – ravi Jul 08 '18 at 11:06
  • Why are you passing an array item to the adapter? `files[0]` – ravi Jul 08 '18 at 11:07
  • @ravi Thanks but the code doesn't work either, files[0] is the file path returned by a dialog – Gerry Jul 08 '18 at 13:01
  • Why do you have `RecyclerView` in ` `ScrollView`? `RecyclerView` does its own scrolling and does not need the assistance of a `ScrollView`. I think that this is the root of the problem. Try changing the `ScrollView` out for `LinearLayout` or other `ViewGroup`. – Cheticamp Jul 08 '18 at 14:46

2 Answers2

0

Change the outer layout with scroll view layout.

<ScrollView
 xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".HexViewActivity">

      <!-- Your stuff here -->

</ScrollView>
Ticherhaz FreePalestine
  • 2,738
  • 4
  • 20
  • 46
0

Have you tried using RecyclerView's attribute app:fastScrollEnabled="true"? Check the full answer here. https://stackoverflow.com/a/46026362/6455501

glagarto
  • 913
  • 8
  • 20