Scrollbar not showing in RecyclerView
Asked Answered
H

12

49

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>
Howie answered 9/12, 2014 at 10:6 Comment(5)
This looks correct. Are you sure there is no theming issue or whatever that renders scrollbars same color with background? Is there a sample project that we can look at ?Ferneferneau
@Michael Schmidt This should work, Just remember to always use android:scrollbars="vertical" when you want to display the scrollbar with recyclerviewHarelip
Maybe you need to add android:scrollbarStyle="outsideOverlay" to your RecyclerView.Reverse
Did you resolve it somehow?Kandykane
Found a good article for scrollbar styling(working for scrollbar and RecyclerView both)... androidopentutorials.com/android-vertical-scrollbar-stylingOffside
T
40

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" />
Thalassic answered 7/1, 2015 at 21:30 Comment(3)
Isn't this the same as that in the question?Jade
-1 as @Jade already pointed out, the OP already has "android:scrollbars" in his code. I also have this in my code, still no scrollbar...Winnie
Maybe for OP it was something else, but by adding android:scrollbars="vertical" it appeared for me.Naquin
G
33

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" />
Geoffrey answered 11/4, 2017 at 8:25 Comment(1)
Note: Setting the background to some color or even transparent is essential on some devices (got a problem with some 8.1 tablet)!Fishbein
S
9

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);
Selfdrive answered 10/7, 2015 at 18:28 Comment(1)
setHasFixSize is for a fix bunch of data.Tartar
A
9

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

Aerial answered 5/8, 2015 at 8:27 Comment(2)
I was able to reproduce it on different emulators, adding background to RecyclerView does help! The correct answer to original question should be setting both android:scrollbars and android:background properties.Synectics
This is the actual solution! ThanksDressy
B
6

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

Berar answered 4/8, 2018 at 12:37 Comment(0)
L
5

You can use from :

setScrollbarFadingEnabled(boolean)

Scrollbar Link

Leatherman answered 7/3, 2015 at 6:1 Comment(1)
The obvious alternative is android:fadeScrollbars="false" in the layout definition.Vinny
F
4

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.

Forint answered 8/3, 2017 at 14:55 Comment(0)
I
2

Try this:

mLayoutManager = new LinearLayoutManager (this);  
mLayoutManager.setSmoothScrollbarEnabled (true);
Imidazole answered 25/12, 2014 at 2:54 Comment(0)
M
0

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));
Malenamalet answered 30/1, 2017 at 14:16 Comment(0)
B
0

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"/>
Brunabrunch answered 17/8, 2017 at 12:51 Comment(0)
O
0

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.

Ordeal answered 14/1, 2019 at 22:46 Comment(0)
Q
0

Using xml android:fadeScrollbars="false"

Using java ScrollView.setScrollbarFadingEnabled(false);

Quintie answered 4/9, 2019 at 2:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.