I've got an App with a LinearLayout to which rectangular fragments are added below each other over time from top to bottom.
At some point the screen is full and the new fragments are "hidden" outside the view of the screen. What I'd like to do then is to make the App scroll to bottom every time a new fragment is added.
A fragment is added everytime a button in the activity is pushed or a checkbox in the above fragment is checked. So I've tried the following in the onClickListeners and in the onCreateView of the fragments:
fm.beginTransaction().add(R.id.activity_uhf_layout, fragment).commit(); //Adding fragment
runOnUiThread(new Runnable() {
@Override
public void run() {
scrollView.scrollTo(0, scrollView.getBottom());
}});
This works sometimes, the fragment is added and the screen scrolls down, but its like 1/8 times.
I've tried other things such as:
scrollView.post(new Runnable() {
@Override
public void run() {
scrollView.scrollTo(0, scrollView.getBottom());
}
});
Which basically gives the same result and I've tried without the Runnable post, which doesn't work at all.
The result I'm getting is that the layout is only scrolled down to the bottom of the fragment which is already present and not all the way down to the end of the new fragment which has just been added by the fragmentmanager.
To me it seems that even though the fragment is added, the LayoutManager hasn't really "detected it" or something similar, but how to get around it, I'm not really sure about.