Reputation: 496
I have a layout which contains button and textView with visibility="gone". This layout is child of scrollView. When button has been pressed the textView visibility is set to "visible" but it overflows the screen (this is why it is in scrollView).
My problem is that I'd like to automatically scroll to the end of the page.
So I've tried:
mySchrollView.fullScroll(View.FOCUS_DOWN);
But unfortunately it doesn't work. It seems that layout will be updated after end of the onClick method (and indeed if I call this method again (new click) it is working).
So I need to refresh the layout or screen before calling fullScroll(...); I tried refreshDrawableState() or forceLayout() but it haven't worked either.
Do you have any idea how to solve it?
Thanks a lot
Upvotes: 1
Views: 3323
Reputation: 31846
you can do:
yourText.setVisibility(View.VISIBLE);
schrollView.post(new Runnable{
@Override
public void run(){
schrollView.fullScroll(View.FOCUS_DOWN);
}
}
And the fullScroll() will be handled when everything else that is already scheduled (e.g. the layout) is completed.
If this for some reason won't work, you can use postDelayed(runnable, 100);
(use the same runnable as in the above example), and the view will scroll after 100 milliseconds.
Upvotes: 2
Reputation: 6728
You can use the method schrollView.smoothScrollTo(x, y). So, in your case the code will look like :
schrollView.smoothScrollTo(0, deviceHeight);
Upvotes: 0
Reputation: 2434
Have you tried calling "schrollView.requestLayout()" or "schrollView.invalidate()"? (btw. shouldn't it be called "scrollView"?)
Upvotes: 0