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

  • Home
  • SEARCH
  • 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 6564807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:00:49+00:00 2026-05-25T14:00:49+00:00

I searched all over, but could not find a solution. I have a view

  • 0

I searched all over, but could not find a solution.

I have a view (lets call it myView) inside a scrollview. myView is bigger than the screen. Since I’m able to get the relative x,y position of my finger inside myView, I would like to make the scrollView autoscroll to the top/bottom when my finger enters a certain top/bottom threshold.
I have some ideas, namely translating the drag location to the screen position but this did not solve this problem.

thanks in advance

cheers

  • 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-25T14:00:50+00:00Added an answer on May 25, 2026 at 2:00 pm

    All right I figured it out by myself.

    First I had to extend the ScrollView class and added an interface OnScrollViewListener.

    public class MyScrollView extends ScrollView {
        private OnScrollViewListener mListener;
    
        public MyScrollView(Context c, AttributeSet attrs) {
           super(c, attrs);
        }
    
        @Override
        protected void onScrollChanged(int l, int t, int oldl, int oldt) {
           super.onScrollChanged(l, t, oldl, oldt);
           if (mListener != null) {
               mListener.onScrollChanged((OnScrollViewListener) this);
           }
        }
    
    
        public void setOnScrollViewListener(OnScrollViewListener listener) {
           mListener = listener;
        }
    
    
        public static interface OnScrollViewListener {
           public void onScrollChanged(OnScrollViewListener listener);
        }
    }
    

    Next in my Activity I inserted a member mScrollDistance that indicates the amount of
    pixels the user scrolls.

    public class ScrollActivity extends Activity {
       private int mScrollDistance;
    
       @Override
       protected void OnCreate(...) {
         ...
    
         final MyScrollView myScrollView = (MyScrollView) findViewById(R.id.scroll_view);
         myScrollView.setOnScrollViewListener(new MyScrollView.OnScrollViewListener() {
    
              public void onScrollChanged(OnScrollViewListener listener) {
                 mScrollDistance = listener.getScrollY();
              }
         }
    
         // making an drag and drop in an view that is inside the MyScrollView
         final LinearLayout myLayout = (LinearLayout)findViewById(R.id.linear_layout);
         myLayout.setOnDragListener(new View.OnDragListener() {
           public boolean onDrag (View v, DragEvent event) {
             int action = event.getAction();
             switch(action) {
                case DragEvent.ACTION_DRAG_STARTED: {
                }
                case DragEvent.ACTION_DRAG_LOCATION: {
    
                  int y = Math.round(event.getY());
                  int translatedY = y - mScrollDistance;
                  int threshold = 50;
                  // make a scrolling up due the y has passed the threshold
                  if (translatedY < threshold) {
                     // make a scroll up by 30 px
                     myScrollView.scrollBy(0, -30);
                  }
                  // make a autoscrolling down due y has passed the 500 px border
                  if (translatedY + threshold > 500) {
                     // make a scroll down by 30 px
                     myScrollView.scrollBy(0, 30);
                  }
                  // listen for more actions here
                  // ...
                }
             }
           }
         }
    

    Now, mScrollDistance gets always a new value and the drag location will be translated to the view location.
    I tested this and it works on layouts/views that are bigger than the screen size.

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have searched but I could not find the following: Process1 transmits data over
IMPORTANT UPDATE This question was made over 9 years ago. It made sense then,
In Asp Net Mvc (3) I like to be able to have a default
This MySQL statement is a bit over my head. I pieced it togather through
Update (21st Sept 2016) - Thanks to Digbyswift for commenting that this solution still
I thought I'd give Helios a try, so I grabbed the latest Java EE
I'm working on a cluster analysis program that takes a set of points S
In Perl one uses: while (<>) { # process files given as command line
For the past 5 months or so, I've spent time learning C# using Andrew
Can anyone point me to the Connect suggention entry for the SELECT-EXEC bug, so

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.