这是一个愚蠢的问题,但我正处于一个应用程序的中间,我想在其中开发一个布局:
此布局垂直和水平滚动。我想在那个表格视图下进行滚动视图,但是如何使它也可以水平滚动。数据来自网络服务,所以我不知道会有多少数据。
所以请指导我。
这是一个愚蠢的问题,但我正处于一个应用程序的中间,我想在其中开发一个布局:
此布局垂直和水平滚动。我想在那个表格视图下进行滚动视图,但是如何使它也可以水平滚动。数据来自网络服务,所以我不知道会有多少数据。
所以请指导我。
水平和垂直滚动都是糟糕的用户体验。我建议你只有一个,我在你的例子中看到的是水平的。如果必须同时拥有这两者,则您可以在创建单元格时创建一个 ListView 并进入您的适配器,以将一个 Horizontal ScrollView 作为一个父级,在其中广告为您的水平 ScrollView 膨胀视图子项。
使用两个滚动视图不是一个好主意。但是,如果需要,您可以做一件事:
创建 XML 布局为:
<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>
并以编程方式在此表中插入记录或行:
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));
}
希望这会帮助你。