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 7660319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:27:00+00:00 2026-05-31T13:27:00+00:00

I have an Android program with a ScrollView that will correctly do an automatic

  • 0

I have an Android program with a ScrollView that will correctly do an automatic scroll when I call the scrollBy method on the emulator on my computer but will not do it on my Android phone.

Here is the code:

public class RecordGameActivity3 extends Activity {
ScrollView myView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.recordgame3);
    myView = (ScrollView)findViewById(R.id.scrollView1);

}

public void addPlayer(View v)
{
    //Removed non-related code

    myView.smoothScrollBy(0, 50);
}
}

Also, the regular scrollBy method doesn’t work or the scrollTo method (although I may just not be using that correctly since that doesn’t work on the computer either). Does anyone have an idea what might be wrong?

EDIT:

My problem as Darrell’s answer showed me was that I was calling my smoothScrollBy method from within a function where I was making changes to the layout that would make the scroll area big enough to be able to be scrolled. Apparently, by the time I was calling it in the function, the changes weren’t actually applied and so it couldn’t be scrolled.

Thus, I changed the code using his advice to the following:

public class RecordGameActivity3 extends Activity {
ScrollView myView;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.recordgame3);
myView = (ScrollView)findViewById(R.id.scrollView1);

// New code that listens for a change in the scrollView and then calls the scrollBy method.
ViewTreeObserver vto = myView.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
    public void onGlobalLayout() {
        myView.smoothScrollBy(0, 100);
    }});

}

public void addPlayer(View v)
{
    //Code that is called on an onClick listener that adds things to the ScrollView making it scrollable.
}
}
  • 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-31T13:27:00+00:00Added an answer on May 31, 2026 at 1:27 pm

    Are you calling smoothScrollBy from the onCreate method? Try waiting until after the views are set up, for instance from onResume. (If you must do it from onCreate you could register a ViewTreeObserver for your view with a OnGlobalLayoutListener, and do the scrolling from there.)

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

Sidebar

Related Questions

I have android.permission.READ_OWNER_DATA but I can't find any reliable code that would explain how
I have an android program that I am making with 4 seekbars, and 4
I have an android program that launches an intent and passes a value to
I have done one program in android using xml parsing but there is an
I have implemented an android program that can receive simple messages using the MJSIP,
In my Android program, I have some code that downloads a file. This works
I made a program on Android. But this is my thesis and I have
i have recently developed a list program in android in which there is an
I have this problem when trying to run hello world program using android SDK.
I'm making an android program that retrieves content of a webpage using HttpURLConnection. I'm

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.