Using:
myLinearLayout.addView(myButton);
he adds them one by one. But if you use
myLinearLayout.addView(myButton, 0);
it adds myButton before the first element in LinearLayout.
In addition to the above code, if you want the HorizontalScrollView to start on the right side, you can use the following code:
new Handler().postDelayed(new Runnable() { @Override public void run() { hScrollView.fullScroll(HorizontalScrollView.FOCUS_RIGHT); } }, 100L);
Armin source share