For part of my app, the user is presented with a list of names and is asked to group them as they see fit.
(Note, the ListView code was copied verbatim from the And
scrollView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
// Ready, move up
scrollView.fullScroll(View.FOCUS_UP);
}
});
The main problem to all these valid solutions is that you are trying to move up the scroll when it isn't drawn on screen yet.
You need to wait until scroll view is on screen, then move it to up with any of these solutions. This is better solution than a postdelay, because you don't mind about the delay.
// Wait until my scrollView is ready
scrollView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
// Ready, move up
scrollView.fullScroll(View.FOCUS_UP);
}
});
This is force scroll for scrollview :
scrollView.post(new Runnable() {
@Override
public void run() {
scrollView.scrollTo(0, 0);
scrollView.pageScroll(View.FOCUS_UP);
scrollView.smoothScrollTo(0,0);
}
});
ScrollView scroll = (ScrollView) findViewById(R.id.addresses_scroll);
scroll.setFocusableInTouchMode(true);
scroll.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
Try
mainScrollView.fullScroll(ScrollView.FOCUS_UP);
it should work.
runOnUiThread( new Runnable(){
@Override
public void run(){
mainScrollView.fullScroll(ScrollView.FOCUS_UP);
}
}