Reputation: 4771
This is a stupid question but i am in middle of an application in which i want to develop a layout as :
This layout scrolls vertically as well as horizontally. I thought to take a scroll view and under that table view, but how to make it scrollable horizontally also. The data is coming from the web service so I don't know what amount of data is going to come.
So please guide me.
Upvotes: 0
Views: 525
Reputation: 476
This is not a good idea to use two scroll view. But if it is needed you can do one thing :
Create XML layout as :
<ScrollView
android:id="@+id/scrollview_vertical_table"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:ignore="UselessParent" >
<TableLayout
android:id="@+id/tablelayout"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:stretchColumns="*" >
</TableLayout>
</HorizontalScrollView>
</LinearLayout>
</ScrollView>
And insert records or rows programmatically in this table as :
TableLayout tableLayoutTransactionLineHeading = (TableLayout) findViewById(R.id.tablelayout);
for(int j=0; j<rows; j++){
TableRow tableRow = new TableRow(this);
tableRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
TextView lineno = new TextView(this);
lineno.setText(lineNo[j]);
lineno.setPadding(10, 10, 10, 10);
lineno.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
tableRow.addView(lineno);
View v = new View(this);
v.setLayoutParams(new TableRow.LayoutParams(1, TableRow.LayoutParams.MATCH_PARENT));
v.setBackgroundColor(Color.rgb(50, 50, 50));
tableRow.addView(v);
tableLayout.addView(tableRow, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT,0f));
}
Hope this will help you.
Upvotes: 0
Reputation: 1265
It is bad user experience to have both scrolling horizontally and vertically. What I sugest you is to have only one and what I see in your example the horizontal one. If is mandatory to have both you can create a ListView and into your adaptor when you create the cell to have a Horizontal ScrollView as a parrent where to ad with inflate the view childs for your horizontal ScrollView.
Upvotes: 1