Android: How to touch a scrollview and show its scroll bar for 2 seconds?

1.1k views Asked by At

I'm working on a requirement that involve scrollview and textview. Clients require that normally the scroll bar is hidden but when user click (touch) the scrollview, which contain a textview, the scrollbar will appear for a short time, say 2 secs, to let user know that the this view is scrollable.

It seems very simple. But I have tried some ways but none of it could achieve this effect. I have tried:

-Assign the scrollview a id, then add onclicklistener function in activity, use setScrollbarFadingEnabled() function combined with a timer. Not work. I even tried to set it to both scrollview and textview.

-use ScrollView.scrollBy(0,1) with OnClickListener. Not work.

Here is my xml part for this section:

  <ScrollView
      android:id="@+id/iScrollView"
      android:layout_width="match_parent"
      android:layout_height="0dip"
      android:layout_gravity="left"
      android:layout_weight="1.5"
      android:background="@drawable/border"
      android:clickable="true" >

    <TextView
        android:id="@+id/iTextview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="bottom"
        android:maxLines="15"
        android:minLines="3"
        android:padding="5dp"
        android:text="Connecting..."
        android:textColor="#777777"
        android:textSize="15sp" >

    </TextView>
</ScrollView>

Is anyone have a simple way to achieve this effect? (I mean, just default android functions, no third party libraries.

Thank you!

1

There are 1 answers

0
Tony On

Try add android:scrollbarFadeDuration="X" to your ScrollView. X is in miliseconds, for instance, if you want the scroll bar to show for 2 seconds, you should have the following code:

<ScrollView
      android:id="@+id/iScrollView"
      android:scrollbarFadeDuration="2000"
      android:layout_width="match_parent"
      android:layout_height="0dip"
      android:layout_gravity="left"
      android:layout_weight="1.5"
      android:background="@drawable/border"
      android:clickable="true" >