I have a ScrollView with a LinearLayout inside an I'm adding TextViews. But I always want the last added TextView to be visible, so I need the ScrollView to scroll to the Bottom, when a TextView is added. I don't know why, but when I call scrollto(), scrollby() or fullScroll() after adding a textview, it only scrolls to the textview before the last one.
Do you know a better way to do this?
Thanks a lot!
Code:
I got a Button, which calls this function:
private void addRound() {
// TODO Auto-generated method stub
TextView newRound = new TextView(Stopwatch.this);
newRound.setText("" + counter + ". - " + timerText());
newRound.setTextSize(20);
newRound.setGravity(Gravity.CENTER);
linlay.addView(newRound);
counter++;
}
After calling this function I call fullScroll().
addRound();
sv.fullScroll(View.FOCUS_DOWN);
sv ist my ScrollView, linlay is the linearlayout inside the scrollview.
Make sure the webpage is long enough so that the browser shows a scroll bar. Once there, to get to the bottom of the page, simply tap the top right corner on your device. In the screenshot below, I need to tap the area where the time is shown. The page will automatically scroll all the way down to the bottom.
ScrollView contentContainerStyle defines the inner container of it, e.g items alignments, padding, etc. Follow this answer to receive notifications.
ScrollView renders all its react child components at once, but this has a performance downside. FlatList renders items lazily, when they are about to appear, and removes items that scroll way off-screen to save memory and processing time.
I reckon it's because the ScrollView is not quite updated by the time you call sv.scrollFull(View.FOCUS_DOWN);
Try the following (to replace your second code sample):
addRound();
sv.post(new Runnable() {
@Override
public void run() {
sv.fullScroll(View.FOCUS_DOWN);
}
});
If the above doesn't work, try the following (it's not an elegant way of doing it but it may work):
addRound();
sv.postDelayed(new Runnable() {
@Override
public void run() {
sv.fullScroll(View.FOCUS_DOWN);
}
}, 100);
Hope this works!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With