/********************************************************************************************
* author:conowen@大钟
* E-mail:conowen@hotmail.com
* http://blog.youkuaiyun.com/conowen
* 注:本文为原创,仅作为学习交流使用,转载请标明作者及出处。
********************************************************************************************/
1、listview与GridView
其实Android本身是有表格控件(GridView)的,但是GridView的每一列的宽度被限定为一样宽,有时设计表格时,列宽不可能为同一宽度,所有可以用ListView控件去实现表格。
2、设计思路:
listview的每一列都是由一个textview去实现,表格的竖线可以通过view控件来绘制。listview每一列的颜色相互不同可以通过复写Adapter的类,然后复写getview方法具体去实现。
3、先看一下效果图:
4、数据库操作部分可以看我之前的博文:http://blog.youkuaiyun.com/conowen/article/details/7306545
本文主要在于竖线的绘制与getview方法的复写。
代码的目录结构如下图所示:
竖线的绘制:
在ListView的布局文件中,每隔一个TextView,就增加一个<View>控件。就是绘制一条竖线的意思。可以设置表格竖线的长度,宽度,颜色等等。
颜色的交互:
首先要知道listview的工作原理,每次得到一个item,listview都会通过getview来绘制一个item,在getview方法中,可以设置这个item的各种属性,如颜色,布局等等。
main.xml
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
LinearLayout
xmlns:android
=
"http://schemas.android.com/apk/res/android"
android:layout_width
=
"fill_parent"
android:layout_height
=
"fill_parent"
android:orientation
=
"vertical"
>
<
LinearLayout
xmlns:android
=
"http://schemas.android.com/apk/res/android"
android:layout_width
=
"fill_parent"
android:layout_height
=
"wrap_content"
android:orientation
=
"horizontal"
>
<
TextView
android:layout_width
=
"40dip"
android:layout_height
=
"30dp"
android:text
=
"序号"
android:textSize
=
"20sp"
/>
<
TextView
android:id
=
"@+id/job"
android:layout_width
=
"200dip"
android:layout_height
=
"30dp"
android:text
=
"岗位名称"
android:textSize
=
"20sp"
/>
<
TextView
android:id
=
"@+id/addr"
android:layout_width
=
"150dip"
android:layout_height
=
"30dp"
android:text
=
"详细地点"
android:textSize
=
"20sp"
/>
<
TextView
android:id
=
"@+id/student"
android:layout_width
=
"100dip"
android:layout_height
=
"30dp"
android:text
=
"工作学生"
android:textSize
=
"20sp"
/>
<
TextView
android:id
=
"@+id/isworking"
android:layout_width
=
"80dip"
android:layout_height
=
"30dp"
android:text
=
"备注"
android:textSize
=
"20sp"
/>
</
LinearLayout
>
<
ListView
android:id
=
"@+id/lv"
android:layout_width
=
"fill_parent"
android:layout_height
=
"wrap_content"
>
</
ListView
>
</
LinearLayout
>
|
<
LinearLayout
xmlns:android
=
"http://schemas.android.com/apk/res/android"
android:layout_width
=
"fill_parent"
android:layout_height
=
"fill_parent"
android:orientation
=
"horizontal"
>
<
View
android:layout_width
=
"0.5px"
android:layout_height
=
"fill_parent"
android:background
=
"#B8B8B8"
android:visibility
=
"visible"
/>
<
TextView
android:id
=
"@+id/id"
android:layout_width
=
"40dip"
android:layout_height
=
"55dip"
android:textColor
=
"#CD3700"
android:textSize
=
"20sp"
/>
<
View
android:layout_width
=
"0.5px"
android:layout_height
=
"fill_parent"
android:background
=
"#B8B8B8"
android:visibility
=
"visible"
/>
<
TextView
android:id
=
"@+id/job"
android:layout_width
=
"200dip"
android:layout_height
=
"wrap_content"
android:textColor
=
"#000000"
android:textSize
=
"17sp"
/>
<
View
android:layout_width
=
"0.5px"
android:layout_height
=
"fill_parent"
android:background
=
"#B8B8B8"
android:visibility
=
"visible"
/>
<
TextView
android:id
=
"@+id/addr"
android:layout_width
=
"150dip"
android:layout_height
=
"wrap_content"
android:textColor
=
"#000000"
android:textSize
=
"17sp"
/>
<
View
android:layout_width
=
"0.5px"
android:layout_height
=
"fill_parent"
android:background
=
"#B8B8B8"
android:visibility
=
"visible"
/>
<
TextView
android:id
=
"@+id/student"
android:layout_width
=
"100dip"
android:layout_height
=
"wrap_content"
android:textColor
=
"#000000"
android:textSize
=
"20sp"
/>
<
View
android:layout_width
=
"0.5px"
android:layout_height
=
"fill_parent"
android:background
=
"#B8B8B8"
android:visibility
=
"visible"
/>
</
LinearLayout
>
|