Scrollbar not showing in RecyclerView

46.7k views Asked by At

I've got a RecyclerView and would like to have scrollbar showing, when it covers more than one page.

I get no scrollbar at all. Any idea?

My layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <CheckBox
        android:id="@+id/cl_only_empty"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:elevation="5dp"
        android:text="@string/cl_only_empty"
        android:textColor="@color/white" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/callsList"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical" />

</LinearLayout>
12

There are 12 answers

0
Mudassir Khan On

Scroller can be set to recyclerview on multiple ways. 1st you can simply add scrollbar in xml and set its property android:fadeScrollbars="false" to always show it.

<android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerViewMachine"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
         android:scrollbars="vertical"
        android:fadeScrollbars="false"
        android:scrollbarThumbVertical="@android:color/darker_gray"
        android:scrollbarSize="5dp"
        android:scrollbarStyle="outsideOverlay"/>

Or you can make a style theme and use it programitically when initializing recyclerview

  <style name="ScrollbarRecyclerView" parent="android:Widget">
        <item name="android:scrollbars">vertical</item>
    </style>

RecyclerView recyclerView = new RecyclerView(new ContextThemeWrapper(context, R.style.ScrollbarRecyclerView));

thanks

0
mio4kon On

Try this:

mLayoutManager = new LinearLayoutManager (this);  
mLayoutManager.setSmoothScrollbarEnabled (true);
3
jbiral On

The solution is to set the vertical (or horizontal) scrollbar in the xml layout:

<android.support.v7.widget.RecyclerView
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:scrollbars="vertical" />
0
tk_ On

Using xml android:fadeScrollbars="false"

Using java ScrollView.setScrollbarFadingEnabled(false);

0
Ayaz Alifov On

If you are fine to set ScrollBar programmatically, then you can use ContextThemeWrapper. First you need to define styling in Style.xml file:

<style name="ScrollbarRecyclerView" parent="android:Widget">
    <item name="android:scrollbars">vertical</item>
</style>

And then apply styling when you initialize your RecylerView:

RecyclerView recyclerView = new RecyclerView(new ContextThemeWrapper(context, R.style.ScrollbarRecyclerView));
2
smbd uknow On

I had the same problem on my old HTC Desire X (api 16) only.
I don't know why, but scollbars of RecyclerView doesn't work properly on this device if the android:background property is not set. Try to set it to any color or to transparent - it works for me, hope it helps you too

0
TheRealChx101 On

Actually, it's because of the theme. The scrollbars are there but can't be seen because they blend with the color on the parent view or some other view in the line of its ancestors.

You can create a drawable shape and give it the color you want then set that as the vertical or horizontal scrollbar drawable. That is, if you do not want to mess around with your theme colors.

0
Dan Ponce On

Besides the android:scrollbars attribute, you should add android:fadeScrollbars attribute in false state like this:

<android.support.v7.widget.RecyclerView
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:scrollbars="vertical"
  android:fadeScrollbars="false"/>

This way, the vertical scrollbar is always showing when it's using more height of the layout permitted.

1
Soe Naing Tun On

use recyclerView as below in xml layout

   <android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:scrollbars="vertical"
    android:fadeScrollbars="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent"  />

and add below code for scrollview in java, it will be okay

 RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
 recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
 recyclerView.setHasFixedSize(true);
1
AudioBubble On

You can use from :

setScrollbarFadingEnabled(boolean)

Scrollbar Link

0
Javith Ahmed Showkathali On

Add the code to Recycler view xml to make scroll bar visible.

<android.support.v7.widget.RecyclerView
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:fadeScrollbars="false"
 android:scrollbars="vertical"
 android:scrollbarSize="@dimen/_2sdp"
 android:scrollbarThumbVertical="@color/white"/>
1
Mandeep Yadav On

Use android:scrollbars attribute "vertical" and android:scrollbarThumbVertical attribute to set the color and android:scrollbarSize attribute to specifiy size:

<android.support.v7.widget.RecyclerView
        android:id="@+id/document_listview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="3dp"
        android:layout_marginTop="3dp"
        android:scrollbars="vertical"
        android:scrollbarThumbVertical="@android:color/darker_gray"
        android:scrollbarSize="5dp"
        android:background="@color/activity_bg"
        android:dividerHeight="4dp" />