Android中控件显示数据表格实现设置行列分割线的方法示例

  

  

虽然Aandroid目前已经有RecyclerView了,非常强大的一个视图,可以直接控制成列表视图以及显示数据表格等,而且画框线也比较方便,但是呢在很多情况下我们不得不仍然使用显示数据表格来实现布的局,那么在这个时候我们又要怎么来对GridViw进行画框线呢,下面将提供两种实现方式,大家可以选择一下

  

  

,,,,1,设置显示数据表格背景色
  

  

,,,2、设置水平和竖直方向间隔:<代码> android: horizontalSpacing 和<代码> android: verticalSpacing
  

  

,,,,,3、设置显示数据表格的项目的背景色及其选中后的颜色
  

  

<强> XML代码如下
  

        & lt;显示数据表格   android: id=" @ id/gridView2 "   android: layout_width=" match_parent "   android: layout_height=" wrap_content "   android: layout_below=" @ id/textView1 "   android: layout_marginTop=" 30 dp "   android:背景=" # 999999 "   android: horizontalSpacing=" 0.5 dp "   android: verticalSpacing=" 0.5 dp "   android:填充=" 2 dp "   android: numColumns=?”比;之前      

<强>项布局
  

        & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比;   & lt; LinearLayout xmlns: android=" http://schemas.android.com/apk/res/android "   android: layout_width=" match_parent "   android: layout_height=" match_parent "   android:取向=按怪薄?   android:重力="中心"   android:背景=癅android:颜色/随心”比;      & lt; TextView   android: id=" @ id/textView1 "   android: layout_width=" wrap_content "   android: layout_height=" wrap_content "   android: textSize=" 20 sp”   android:填充=" 10 dp”   android:文本=" TextView "/比;      & lt;/LinearLayout>之前      

  

这种方式就是设置项目的选择器的<代码> android:背景属性来实现的
  

  

<强> gv_selector代码
  

        & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比;   & lt;选择xmlns: android=" http://schemas.android.com/apk/res/android "比;   & lt;项目   android: state_selected=" true "比;   & lt;形状android:形状=熬匦巍北?   & lt;固体   android:颜色=" # CCCCCC”/比;   & lt;中风android:宽度=" 1.0 px”android:颜色=" # 999999 "/比;   & lt;/shape>   & lt;/item>   & lt;项目   android: state_pressed=" true "比;   & lt;形状android:形状=熬匦巍北?   & lt;固体   android:颜色=" # CCCCCC”/比;   & lt;中风android:宽度=" 1.0 px”android:颜色=" # 999999 "/比;   & lt;/shape>   & lt;/item>   & lt; item>   & lt;形状android:形状=熬匦巍北?   & lt;中风android:宽度=" 1.0 px”android:颜色=" # 999999 "/比;   & lt;/shape>   & lt;/item>   & lt;/selector>之前      

至此两种方法已经写完了,有细心的朋友可能会发现第二种方法的中间的网格线比边线要粗两倍,这也是第二种方法的一个不足的地方

  

  

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流。

Android中控件显示数据表格实现设置行列分割线的方法示例