I have an application with LinearLayout, with which rectangular fragments are added under each other with time from top to bottom.
At some point, the screen is full, and new fragments are βhiddenβ outside the screen. What I would like to do is scroll down the application each time a new snippet is added.
A fragment is added each time a button in action is pressed or a checkmark is selected in the fragment indicated above. So I tried the following in onClickListeners and in onCreateView snippets:
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 sometimes works, a fragment is added, and the screen scrolls down, but it is like 1/8 times.
I 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 tried without a Runnable message, which doesn't work at all.
The result that I get is that the layout only scrolls to the bottom of the fragment that is already present, and not all the way to the end of the new fragment that has just been added using the managermanager.
It seems to me that even if a fragment is added, the LayoutManager did not actually "detect" it or something like that, but how to get around it, I'm not quite sure.