Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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.</p> <p>============================</p> <pre><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 &lt; 0) { // If user is moving finger up screen if (mScrollY &gt; 0) { // and we are not at top of text int m = mScrollY - mMinScroll; // Do not go beyond top of text if (m &lt; 0){ m = mScrollY; }else m = mMinScroll; scrollBy(0, -m); // Scroll the text up } } else if (deltaY &gt; 0) { // The user finger is moving up int max = getLineCount() * getLineHeight () - sHeight; // Set max up value if (mScrollY &lt; 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) &gt; 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 } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload