Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6069927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:52:33+00:00 2026-05-23T09:52:33+00:00

I have implemented the editor code from the Android Note Pad sample code. Now

  • 0

I have implemented the editor code from the Android Note Pad sample code. Now I would like to add the ability to vertically fling scrolls the lines of text. An example of what I want to accomplish is the fling scrolling of the option lines in the Andorid

I Googled for examples of scroller and fling but I can not find anything that fits what I need to to. I have not found anything that even remotely fits what I am trying to do.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:52:34+00:00Added an answer on May 23, 2026 at 9:52 am

    I have developed the answer to my question through blood, sweat and tears. I will post it here in hope that it will help someone else. The following methods are placed within the LinedEditText class from the Android Note Pad sample code.

    ============================

        public void InitScroller(Context context) {
            mScroller = new Scroller(context);       // Get a scroller object
            mScrollY = 0 ;                          // Set beginning of program as top of screen.
            mMinScroll = getLineHeight ()/2;            // Set minimum scroll distance
            mFlingV = 750;                         // Minimum fling velocity
    
        }
    
     @Override
     public boolean onTouchEvent(MotionEvent event) {
         super.onTouchEvent(event);
    
      if (mVelocityTracker == null) {                       // If we do not have velocity tracker
             mVelocityTracker = VelocityTracker.obtain();   // then get one
         }
         mVelocityTracker.addMovement(event);               // add this movement to it
    
      final int action = event.getAction();  // Get action type
      final float y = event.getY();          // Get the displacement for the action
    
      switch (action) {
    
         case MotionEvent.ACTION_DOWN:          // User has touched screen
             if (!mScroller.isFinished()) {     // If scrolling, then stop now
                 mScroller.abortAnimation();
             }
             mLastMotionY = y;                  // Save start (or end) of motion
             mScrollY = this.getScrollY();              // Save where we ended up
             mText.setCursorVisible (true);
             didMove = false;
    
             break;
    
         case MotionEvent.ACTION_MOVE:          // The user finger is on the move
             didMove = true;
             final int deltaY = (int) (mLastMotionY - y);  // Calculate distance moved since last report
             mLastMotionY = y;                             // Save the start of this motion
    
             if (deltaY < 0) {                              // If user is moving finger up screen
                 if (mScrollY > 0) {                        // and we are not at top of text
                     int m = mScrollY - mMinScroll;         // Do not go beyond top of text
                     if (m < 0){
                         m = mScrollY; 
                     }else m = mMinScroll;
    
                  scrollBy(0, -m);                           // Scroll the text up
                 }
             } else 
                 if (deltaY > 0) {                           // The user finger is moving up
                     int max = getLineCount() * getLineHeight () - sHeight;   // Set max up value
                     if (mScrollY < max-mMinScroll){
                         scrollBy(0, mMinScroll);           // Scroll up
                     }
                 }
             postInvalidate();
             break;
    
         case MotionEvent.ACTION_UP:                       // User finger lifted up
             final VelocityTracker velocityTracker = mVelocityTracker;      // Find out how fast the finger was moving
             velocityTracker.computeCurrentVelocity(mFlingV);          
             int velocityY = (int) velocityTracker.getYVelocity();
    
             if (Math.abs(velocityY) > mFlingV){                                // if the velocity exceeds threshold
                 int maxY = getLineCount() * getLineHeight () - sHeight;        // calculate maximum Y movement
                 mScroller.fling(0, mScrollY, 0, -velocityY, 0, 0, 0, maxY);    // Do the filng
             }else{
                 if (mVelocityTracker != null) {                                // If the velocity less than threshold
                     mVelocityTracker.recycle();                                // recycle the tracker
                     mVelocityTracker = null;
                 }
             }
             break;
         }
    
         mScrollY = this.getScrollY();              // Save where we ended up
    
      return true ;                                 // Tell caller we handled the move event
     }
    
    
    
     public void computeScroll() {                  // Called while flinging to execute a fling step
         if (mScroller.computeScrollOffset()) {      
             mScrollY = mScroller.getCurrY();       // Get where we should scroll to 
             scrollTo(0, mScrollY);                 // and do it
             postInvalidate();                      // the redraw the sreem
         }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following Spring code, taken from a textbook, that's returning a NotWritablePropertyException.
I have implemented a graph editor with Eclipse EMF and GMF frameworks. After completing
I implemented the plist in my iOS game following this tutorial: Now I have
I have implemented what I thought was a pretty decent representation of MVC in
I have implemented a simple file upload-download mechanism. When a user clicks a file
I have implemented a python webserver. Each http request spawns a new thread. I
I have implemented a SAX parser in Java by extending the default handler. The
I have implemented VirtualPathProvider class so I can keep all my views in the
I have implemented tracing based on System.Diagnostics. I am also using a System.Diagnostics.TextWriterTraceListener, and
We have implemented a popup window as a modal dialog using the IE method:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.