Bialy Bialy - 5 months ago 8
Android Question

Scrolling a ScrollView to a specific id

I have a Scrollview in my activity , I want when I press a button the view scrolls down to a specific ID in the view. After some search here I found I can use this code

scrollView.post(new Runnable() {
@Override
public void run() {
scrollView.fullScroll(View.FOCUS_DOWN);
}
});


but it scrolls all the page down. I want to scroll to a specific ID in the middle of the view

Answer
ScrollView scrollView = (ScrollView) findViewById(R.id.scroll_view);
scrollView.postDelayed(new Runnable() {
     public void run() {
          scrollView.scrollTo(0, (int)view.getY());
     }
}, 100);

view = your view you want to scroll to