在我的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