1

I was trying to implement the scrollView and scroll using the scrollbar. But, It isn't working.

This is whole xml file.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".ScrollingActivity">
    <ScrollView
        android:id="@+id/scroll"
        android:layout_width="wrap_content"
        android:scrollbars="vertical"
        android:scrollbarThumbVertical="@color/teal_200"
        android:scrollbarSize="20dp"
        android:layout_height="wrap_content">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/large_text"/>
    </ScrollView>
</LinearLayout>

and java is default file.

Main Issue

ScrollBar is appearing and can be seen by user. ScrollBar changes the position as well. But, when User wants to scroll using scrollbar, scrollbar isn't responding. It's like we cannot touch the scrollbar, Instead the textView is selected will be swiped.

My Reasearch

Before anything, I did try to implement GestureDetecter as well as went through several links and google.

  1. How to scroll using custom scrollbars in android WebView?

  2. Gesture detection and ScrollView issue

These are just two links which is most related to my issue. So, I tried to implement customScrollView as well. Which resulted in app crash. There was use of deprecated api too. So, I didn't bother to solve the issue. Instead I focused on replacing that api and getting that class working. But, unfortunately even I got the replacement it wasn't working. I skipped the file because it was way lengthy.

  • Are you tried only one TextView with ScrollView? – Elango Jun 21 '21 at 18:24
  • Yes... It's the default large text from scrolling activity in create new project menu. I first tried that project. But, It wasn't working in that too. So, I simplified it. And kept only needed elements. – Anirudhdhsinh Jadeja Jun 22 '21 at 04:32

1 Answers1

0

You no need to use ScrollBar

Try with is

In you XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".ScrollingActivity">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:scrollbars = "vertical"
            android:text="@string/large_text"/>
  
</LinearLayout>

And in your java

yourtextview.setMovementMethod(new ScrollingMovementMethod());
Elango
  • 406
  • 3
  • 11