我在ScrollView
上滚动的TableLayout
有问题,该代码的TableRows
通过代码添加。由于某种原因,如果我使用HorizontalScrollView
这将水平滚动,但不垂直(显然),而我需要垂直和水平。但是,使用带有水平和垂直滚动条的ScrollView
不能。Scrollview不适用于TableLayout
我已经定义了一个ScrollView
和在下面的XML一个TableLayout
,
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="horizontal|vertical" >
<TableLayout
android:id="@+id/table_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableLayout>
</ScrollView>
我然后添加tablerows到tablelayout如下,
table = (TableLayout) findViewById(R.id.table_id);
for (int i = 0; i < 9; i++) {
TextView headerRow = new TextView(getApplicationContext());
// set up the keyboard so it doesn't go fullscreen
//firstEditText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
switch (i) {
case 0:
headerRow.setText("B/Sight");
break;
case 1:
headerRow.setText("Int/Sight");
break;
case 2:
headerRow.setText("F/Sight");
break;
case 3:
headerRow.setText("Rise");
break;
case 4:
headerRow.setText("Fall");
break;
case 5:
headerRow.setText("Reduced Level");
break;
case 6:
headerRow.setText("Lat");
break;
case 7:
headerRow.setText("Long");
break;
case 8:
headerRow.setText("Remark");
break;
}
setCellProperties(headerRow);
firstRow.addView(headerRow);
}
table.addView(firstRow);
凡setCellProperties()
是,
void setCellProperties(TextView txtView) {
txtView.setPadding(30, 15, 30, 15);
txtView.setTextColor(Color.BLACK);
txtView.setBackgroundResource(R.drawable.cell_shape);
txtView.setGravity(Gravity.CENTER);
}
然后我使用数据添加更多行与上述相同的程序。我曾尝试在其他布局(如LinerLayout)中包装此ScrollView,但我无法破解它。可能值得一提的是,这将在Landscape not Portrait中进行查看。
欢迎@ Mika571和ScrollView应该是根布局。它不应该包含在Linearlayout中 –