在我的Android应用程序中,有一个屏幕,其中一些数据以表格格式显示。这个表格将有大约5列和至少50行。Android中的表格
我该如何在android中创建表格?
我搜遍了,每个人似乎都建议为每个单元格使用TableLayout和textView。由于有许多textView组件,使用这种技术似乎有点困难。
有没有其他解决方案呢?
在我的Android应用程序中,有一个屏幕,其中一些数据以表格格式显示。这个表格将有大约5列和至少50行。Android中的表格
我该如何在android中创建表格?
我搜遍了,每个人似乎都建议为每个单元格使用TableLayout和textView。由于有许多textView组件,使用这种技术似乎有点困难。
有没有其他解决方案呢?
使用ListView控件使用自定义适配器,创建列表视图项目五周的TextView的栏目.. 创建列表项这样 row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:text="TextView" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
<TextView android:text="TextView" android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
<TextView android:text="TextView" android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
<TextView android:text="TextView" android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
<TextView android:text="TextView" android:id="@+id/textView5" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
</LinearLayout>
TableLayout lTableLayout;
lTableLayout = (TableLayout)findViewById(R.id.tblayout);
for(int i=0;i<10;i++){
TableRow tr1 = new TableRow(this);
tr1.setPadding(0, 5, 0, 0);
lTableLayout.addView(tr1, LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
TextView tv11 = new TextView(this);
tv11.setPadding(2, 0, 0, 0);
tv11.setTextSize(12);
tr1.addView(tv11,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); // Can give width and height in numbers also.
}
这些将采取表中创建10行1个TextView的每一行布局。 在您的xml文件中采用一个表格布局,如下所示:
<TableLayout
android:id="@+id/tblayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</TableLayout>
谢谢你的回答。我能够使用上述创建。但是我想知道如何将特定的样式应用到表格Row,这种情况下的文本视图。样式在styles.xml中定义。 – Nini 2012-04-17 11:40:38
http://stackoverflow.com/questions/2016249/how-to-programmatically-setting-style-attribute-in-a-view可以帮助你。 – Dhruvisha 2012-04-17 11:59:17
背景和文字颜色不是问题。但是当我们从样式或膨胀文本视图获取属性时,textview的宽度没有设置。我想知道为什么只有宽度不起作用。 – Nini 2012-04-17 12:30:13
您想通过代码进行操作吗?或通过XML? – Dhruvisha 2012-04-05 10:23:15
一切都很好。 – Nini 2012-04-05 11:18:57