I implemented this code.
ScrollView sv = new ScrollView(StackDemosActivity.this);
TableLayout t1 = new TableLayout(StackDemosActivity.this);
TableRow.LayoutParams tableRowParams = new TableRow.LayoutParams(
TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.MATCH_PARENT);
tableRowParams.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL;
for (int i = 0; i < 25; i++) {
TableRow tr = new TableRow(StackDemosActivity.this);
TextView txt_peron_name = new TextView(StackDemosActivity.this);
txt_peron_name.setTextColor(Color.BLACK);
txt_peron_name.setTextSize(15);
txt_peron_name.setText("Hello");
tr.addView(txt_peron_name);
tr.setGravity(Gravity.RIGHT);
t1.addView(tr, tableRowParams);
}// End of For Loop
ll = (LinearLayout) findViewById(R.id.ll);
ll.removeAllViews();
sv.addView(t1);
ll.addView(sv);
I changed some code like taking LinearLayout then adding ScrollView inside. So this was minor changes I have made.
Output