3

How do I get the amount of pixels which a user has scrolled in a scroll view. I have a scroll view which contains lot of texts. I also have a button at bottom of the screen. What I want is to change text on the button to the amount of scrolling done in the scroll view.

this is my scroll view:

 <ScrollView 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/scrollverbal"
    >

    <LinearLayout 
        android:orientation="vertical"
        android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    >

    <TextView 
         android:layout_width="match_parent"
    android:layout_height="wrap_content"
     android:id="@+id/verbalintro"
     android:textSize="15sp"
     />

    <View 
        android:layout_width="match_parent"
        android:layout_height="10dp"
    />

    <TextView 
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:id="@+id/verqstns"
         android:textSize="15sp"
    />

  </LinearLayout>  

</ScrollView>

and my button is

 <Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="15" 
android:background="@android:color/transparent"
android:textSize="20sp"
android:textStyle="bold"
android:drawablePadding="-5sp"
android:paddingLeft="10sp"
android:drawableLeft="@drawable/tick"
/>

I read that it can be done using getScrollY() method. but don't know how to use it programatically.

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Abhinav Raja
  • 349
  • 1
  • 5
  • 25

2 Answers2

6

Try this, where scrollX is scrolled pix in x axis and scrollY in Y axis

scrollX = scrollView.getScrollX();
scrollY = scrollView.getScrollY();

Refer this for doc

Adhikari Bishwash
  • 2,770
  • 28
  • 32
0

this may help you

https://stackoverflow.com/a/5966375/472336

set click listener for your btn findview by id your scroolview and on that call this method and set it as buttons text

Community
  • 1
  • 1
Pramod
  • 1,123
  • 2
  • 12
  • 33
  • like this: final Button answer= (Button) findViewById(R.id.answernumber); answer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub ScrollView scrver = (ScrollView) findViewById(R.id.scrollverbal); int scrollposition = scrver.getScrollY(); answer.setText(scrollposition); } }); – Abhinav Raja Feb 14 '14 at 09:38
  • all i want is the text should change as the user scrolls – Abhinav Raja Feb 14 '14 at 09:40
  • For this you have to set text of button inside scroll listener of your scrollview for that this link may help you http://stackoverflow.com/a/10713501/472336 – Pramod Feb 19 '14 at 06:52