作者:DevDiv移动开发社区pshchao
声明,代码中一部分是摘自网络上,并不完全是自己写的
经过几天的请教,查等,艰辛的过程,加上自己的修改,终于实现了自己满意的listview    可以水平,垂直滚动,可以响应checkbox,textview的点击事件,可以任意布局,加入任意控件。    跟大家分享是希望像我一样的新手少走弯路。
代码是完整的,不用任何修改即可实现图效果图中所示的效果    ,demo中用到的图片已上传
如有不足之处,请指正,共同交流,共同进步
1.1    代码:
<?xml    v ersion="1.0"    e ncoding="utf-­‐8"?>
<TableLayout    a ndroid:id="@+id/tableLayout1"
android:layout_width="fill_parent"    a ndroid:layout_height="fill_parent"
xmlns:android="schemas.android/apk/res/android">
<TableRow    a ndroid:layout_width="fill_parent"
android:layout_height="wrap_content"    a ndroid:id="@+id/listview">
<TextView    a ndroid:layout_width="80dip"    a ndroid:gravity="center"
android:layout_height="wrap_content"
android:textColor="#42AF40"
android:drawableRight="@drawable/line_y"
android:id="@+id/imageid_textview"></TextView>
<TextView    a ndroid:layout_width="100dip"
android:layout_height="wrap_content"
android:textColor="#42AF40"
© 2007-2011 DevDiv移动开发社区www.devdiv
android:drawableRight="@drawable/line_y"    android:gravity="center"
android:id="@+id/taskid_textview"></TextView>
<TextView    a ndroid:layout_width="100dip"    a ndroid:gravity="center"                                                                                                                                    android:layout_height="wrap_content"
android:textColor="#42AF40"
android:drawableRight="@drawable/line_y"    android:id="@+id/machineid_textview"></TextView>
<TextView    a ndroid:layout_width="140dip"    a ndroid:gravity="center"                                                                                                                                    android:layout_height="wrap_content"
android:textColor="#42AF40"
android:drawableRight="@drawable/line_y"    android:id="@+id/position"></TextView>
<TextView    a ndroid:layout_width="120dip"    a ndroid:gravity="center"                                                 
                                                                                  android:layout_height="wrap_content"
android:textColor="#42AF40"
android:drawableRight="@drawable/line_y"    android:id="@+id/taskstatus"></TextView>
<TextView    a ndroid:layout_width="80dip"    a ndroid:gravity="center"                                                                                                                                    android:layout_height="wrap_content"
android:textColor="#42AF40"
android:drawableRight="@drawable/line_y"    android:id="@+id/a07_ls_button"></TextView>
© 2007-2011 DevDiv移动开发社区www.devdiv
Error!    N o    t ext    o f    s pecified    s tyle    i n    d ocument.    E rror!    N o    t ext    o f    s pecified    s tyle    i n    d ocument.
<CheckBox    a ndroid:textColor="#42AF40"    a ndroid:layout_width="80dip"                                                                                                                                    android:gravity="center"
android:layout_height="wrap_content"
android:drawableRight="@drawable/line_y"
android:id="@+id/a07_ls_checkbox"></CheckBox>
</TableRow>
</TableLayout>
<LinearLayout    a ndroid:id="@+id/relativeLayout1"
android:layout_width="fill_parent"    a ndroid:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="schemas.android/apk/res/android">
<HorizontalScrollView
android:id="@+id/HorizontalScrollView01"
android:layout_height="400px"
android:layout_width="fill_parent"
android:layout_weight    =    "1"
>
<LinearLayout    a ndroid:layout_width="fill_parent"
android:layout_height="fill_parent"    a ndroid:layout_weight="1">
<!-­‐-­‐    数据表格    -­‐-­‐>
<ListView    a ndroid:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/taskok_listView"
android:scrollbars="vertical">
5
© 2007-2011 DevDiv 移动开发社区www.devdiv        © 2007-2011 DevDiv 移动开发社区www.devdiv
</ListView>
</LinearLayout>
</HorizontalScrollView>
<LinearLayout    a ndroid:layout_width="fill_parent"
android:layout_height="fill_parent"    a ndroid:layout_weight="4"
android:orientation="horizontal"
xmlns:android="schemas.android/apk/res/android">
<Button    a ndroid:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/taskok_button"
android:id="@+id/taskok_button">
</Button>
<Button    a ndroid:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sendback_button"
android:id="@+id/sendback_button">
</Button>
<Button    a ndroid:id="@+id/invalidate_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/invalidate_button"></Button>
</LinearLayout>
Error!    N o    t ext    o f    s pecified    s tyle    i n    d ocument.    E rror!    N o    t ext    o f    s pecified    s tyle    i n    d ocument.
<LinearLayout    a ndroid:layout_height="fill_parent"
android:layout_width="fill_parent"    a ndroid:layout_weight="4"
android:orientation="horizontal"
xmlns:android="schemas.android/apk/res/android">
<Button    a ndroid:id="@+id/back_button"    a ndroid:layout_width="wrap_content"                                                                                                    android:layout_height="wrap_content"
android:text="@string/back_button"></Button>
<Button    android:id="@+id/daohang_button"    android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/daohang_button"></Button>
</LinearLayout>
</LinearLayout>
activity代码如下:
package    A ndroid.GPSTest;
import    j ava.util.ArrayList;
import    j ava.util.HashMap;
import    j ava.util.List;
import    j ava.util.Map;
android layout布局
import    A ndroid.GlobalFunc.GlobalFunc;
import    a ndroid.app.Activity;
7