I am using a table that needs both vertical and horizontal scrolling. I used two scroll view to do so as below. Is it possible to use single one for both purposes? Meaning enable one scrollview as horizontal and vertical:
LinearLayout contentView = (LinearLayout) findViewById(R.id.contentView);
TableLayout tableLayout = new TableLayout(getApplicationContext());
TableRow tableRow;
TextView textView;
for (int i = 0; i <28; i++) {
tableRow = new TableRow(getApplicationContext());
for (int j = 0; j < 16; j++) {
textView = new TextView(getApplicationContext());
textView.setText("test");
textView.setPadding(20, 20, 20, 20);
tableRow.addView(textView);
}
tableLayout.addView(tableRow);
}
ScrollView scroll = new ScrollView(MainActivity.this);
scroll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
scroll.addView(tableLayout);
HorizontalScrollView horizontalScroll = new HorizontalScrollView(MainActivity.this);
horizontalScroll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
horizontalScroll.addView(scroll);
contentView.addView(horizontalScroll);
You can Use the custom scroll view code that you can use in your xml file. This is one small sample for Vertical Scroll View in this you can use Horizontal also