表中的Andr​​oid [英] Table in android

查看:120
本文介绍了表中的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Andr​​oid应用程序存在与在表格的形式来显示一些数据的屏幕。这个表将有大约5列和至少50行。

我怎么做我在android系统中创建一个表?

我搜索过,每个人都似乎建议使用TableLayout和TextView的每个细胞。利用这种技术似乎有点困难,因为有很多的TextView组件。

有没有其他的解决方案呢?


解决方案

  TableLayout lTableLayout;
lTableLayout =(TableLayout)findViewById(R.id.tblayout);
对(INT I = 0; I&小于10;我++){
的TableRow TR1 =新的TableRow(本);
tr1.setPadding(0,5,0,0);
lTableLayout.addView(TR1,LayoutParams.WRAP_CONTENT,
                        LayoutParams.WRAP_CONTENT);
TextView的tv11 =新的TextView(本);
tv11.setPadding(2,0,0,0);
tv11.setTextSize(12);
tr1.addView(tv11,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); //可以给在数量上也宽度和高度。}

这将创建10行,并采取表格布局每排1 TextView中。
采取一表的布局在XML文件象下面这样:

 < TableLayout
                    机器人:ID =@ + ID / tblayout
                    机器人:layout_width =FILL_PARENT
                    机器人:layout_height =WRAP_CONTENT>
< / TableLayout>

In my android application there is a screen with some data to be displayed in table format. This table will have around 5 columns and at least 50 rows.

How do I do i create a table in android?

I searched through and everybody seems to recommend to use TableLayout and textView for each cell. Using this technique seems to be a bit difficult as there are lots of textView Components.

Is there any other solution to this?

解决方案

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.

}

These will create 10 rows and 1 textview in each row in taken table layout. take one table layout in your xml file like below :

<TableLayout
                    android:id="@+id/tblayout"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content" >
</TableLayout>

这篇关于表中的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆