I\'m building a chat-like application that displays text the user inputs to the screen using a scrollview. What I\'m doing is auto-scrolling the scrollview down as more text
@Override
public void onClick(View v) {
scview_ashora = findViewById(R.id.scview_ashora);
scview_ashora.fullScroll(ScrollView.FOCUS_DOWN);
scview_ashora.postDelayed(new Runnable() {
@Override
public void run() {
//replace this line to scroll up or down
scview_ashora.fullScroll(ScrollView.FOCUS_DOWN);
}
}, 1000000L);
}
});
I looked around, and found that some other people have run into the same problem.
I solved this problem using this piece of code:
final ScrollView scrollView = (ScrollView) findViewById(R.id.scroll_view);
scrollView.post(new Runnable() {
public void run() {
scrollView.fullScroll(View.FOCUS_DOWN);
}
});
Hopefully this can help somebody out there!
Its late but may help some one with this issue.. It takes around 200 miniseconds to add the last element and update it for a scrollView so this will surely work.
void scrollDown()
{
Thread scrollThread = new Thread(){
public void run(){
try {
sleep(200);
ChatActivity.this.runOnUiThread(new Runnable() {
public void run() {
myScrollView.fullScroll(View.FOCUS_DOWN);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
};
scrollThread.start();
}
Just call scrollDown();
after adding element to scrollView.