如何在android中滚动tableview
我有一个tableview,我想滚动,因为数据没有显示完整。如何在android中滚动tableview
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="0,1,2,3,4"
android:id="@+id/maintable" >
</TableLayout>
这是我tablelayout,如果我在<ScrollView> </Scrollview>
应用crashs包裹它,如果我打开活动。怎么做?
你应该真的把你试过的代码弄糟了你的应用程序和崩溃的原因。原始帖子中没有有价值的信息。
Ehhh ...你尝试过这么简单吗?我使用几个地方的示例.xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout android:id="@+id/score_table"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow android:id="@+id/header"/>
</TableLayout>
</ScrollView>
对我来说绝对没问题。显然,如果您没有使用TableRow,则无需包含TableRow。
这将滚动钻孔表我不想滚动标题然后呢? – CoronaPintu 2014-02-13 04:54:40
创建行动态 在这里,我把一个小例子,
main.xml中
<Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Add row"></Button>
<ScrollView android:id="@+id/ScrollView01" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TableLayout android:id="@+id/TableLayout01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:stretchColumns="0">
<TableRow android:id="@+id/TableRow01" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:id="@+id/TextView01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="textfield 1-1"></TextView>
<CheckBox android:id="@+id/CheckBox01" android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox>
</TableRow>
</TableLayout>
</ScrollView>
活动是
public class tablelayout extends Activity implements OnClickListener {
/** Called when the activity is first created. */
//initialize a button and a counter
Button btn;
int counter = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setup the layout
setContentView(R.layout.main);
// add a click-listener on the button
btn = (Button) findViewById(R.id.Button01);
btn.setOnClickListener(this);
}
// run when the button is clicked
public void onClick(View view) {
// get a reference for the TableLayout
TableLayout table = (TableLayout) findViewById(R.id.TableLayout01);
// create a new TableRow
TableRow row = new TableRow(this);
// count the counter up by one
counter++;
// create a new TextView
TextView t = new TextView(this);
// set the text to "text xx"
t.setText("text " + counter);
// create a CheckBox
CheckBox c = new CheckBox(this);
// add the TextView and the CheckBox to the new TableRow
row.addView(t);
row.addView(c);
// add the TableRow to the TableLayout
table.addView(row,new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
}
}
您可以创建表行,当你的代码需要时。我认为它是在按钮点击。
希望这会有所帮助。
而且这里还有一个example。
不,这不是问题,生病让我的表像我想要的。我用这个:[link](http://www.warriorpoint.com/blog/2009/07/01/android-creating-tablerow-rows-inside-a-tablelayout-programatically/)。但它不显示屏幕上的所有内容,所以我想滚动,但那不起作用 – Mark 2011-03-22 13:47:55
你能解释哪部分不显示,是水平还是垂直? – 2011-03-22 16:04:38
还有一件事,如果你想滚动,你的表必须在滚动视图。 – 2011-03-22 16:10:36
android listview直接滚动时,列表大于大小,所以你有没有尝试把许多行在表视图? – Siten 2011-03-22 13:09:15
不,我以为我必须使用tablelayout这个?因为我只显示一张桌子? ^^ – Mark 2011-03-22 13:18:38
你可以把你的完整的XML文件? – 2011-03-22 13:22:47