0
我是android中的新手,我手动创建了一个tablelayout,每行5行,每行10列。我设法使用linearlayout在每个单元格中组合imageview和textview。但我的代码很长,运行程序时我的eclipse崩溃了。如何在Android中的每个单元格中使用ImageView和TextView动态创建tablelayout?
我看到了一些关于在每个单元格中动态创建带有图像视图的tablelayout的代码,但是我无法找到关于在每个单元格中组合imageview和textview的内容。请帮忙...
这里是我的xml的一部分。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shrinkColumns="*"
android:stretchColumns="*"
>
<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="100dp"
>
<LinearLayout
android:id="@+id/l1"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:background="@android:drawable/list_selector_background">
<ImageView
android:id="@+id/s1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/chair" />
<TextView
android:id="@+id/t1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="001" />
</LinearLayout>
</TableRow>
</TableLayout>
<LinearLAyout>
我希望它是这样的东西,我可以点击每个单元格,所以我认为listview不能解决我的问题。如果它能支持我的问题,我也不太了解。
喜PravinCG,感谢您的答复。我编辑了我的问题以避免混淆。我认为listview不能解决我的问题。我不太了解listview,所以我不知道它是否适合我的问题。 – oyan11