在使用 GridView 网格布局时,默认情况下 GridView  是没有网格线的,但是有些时候我们需要让GridView显示分割线,怎么办呢?
查了不少资料,找到了一种为GridView添加网格线的方法。实际上,该网格线是通过设置GridView各子项的间隔,并分别设置GridView背景色与子项背景色实现的。

实现方法 
1、设置GridView背景色,设置水平间方向间隔属性值android:horizontalSpacing和竖直方向间隔属性值android:verticalSpacing

2、设置GridView子项背景色,要求 子项背景色跟GridView背景色不一致。

  1. <GridView
  2. android:id="@+id/mGridView"
  3. android:layout_width="match_parent"
  4. android:layout_height="wrap_content"
  5. android:numColumns="2"
  6. android:stretchMode="columnWidth"
  7. android:horizontalSpacing="2dp"
  8. android:verticalSpacing="2dp"
  9. android:background="@color/yulore_light_blur"
  10. android:visibility="gone" />
 

grid_item.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="wrap_content"
  4. android:layout_height="wrap_content"
  5. android:layout_margin="1dp"
  6. android:background="@color/yulore_blur">
  7. <TextView
  8. android:id="@+id/tv_category_name"
  9. android:layout_width="wrap_content"
  10. android:layout_height="wrap_content"
  11. android:layout_centerInParent="true"
  12. android:textColor="@color/yulore_black"
  13. android:text="合租房"
  14. android:textSize="18sp"
  15. android:singleLine="true"
  16. android:padding="15dp"/>
  17. </RelativeLayout>

运行效果(二级分类GridView):

Android GridView 添加 网格线解决办法的更多相关文章

  1. android RelativeLayout 内容居中解决办法

    android RelativeLayout 内容居中解决办法:   使用Linearlayout本来利用父控件的gravity属性是很好解决的.但是对应RelativeLayout虽然有 gravi ...

  2. Android 常见异常及解决办法

    Ø  前言 本文主要记录 Android 的常见异常及解决办法,以备以后遇到相同问题时可以快速解决. 1.   java.lang.NullPointerException: Attempt to i ...

  3. Android Studio 常见异常解决办法

    Error:Failed to crunch file D:\Englis_installation_directory\AndroidStudio\AndroidWorkSpace\YoukAndr ...

  4. Visual Studio Xamarin编译Android项目出错的解决办法

    安装完Xamarin后,编译Android项目时,你会发现好长时间进度都不动,当你取消编译后,会发现其实是出错了,就是因在Android项目在第一次编译时要去google网站上下一个andorid s ...

  5. 无法打开Android SDK Manager的解决办法

    不知道从什么时候开始,打开Android的SDK Manager.exe时,命令行窗口一闪就自动关掉了. 想更新一些Android的东西都更新不了. 查了一下,解决办法是: 环境变量的系统变量Path ...

  6. [转]编译Android源代码常见错误解决办法

    1. 编译时出现/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../libz.so when ...

  7. Android编译安装失败解决办法

    今天用AndroidStudio开发了一个手机App玩玩,但是偶然遇到一个问题,自己手机上测试得劲的很,分享给朋友做测试,但是nie,意外出现了.... 两个人都给我说个安装失败,这个就比较尴尬了,找 ...

  8. Android layout_margin 无效的解决办法

    http://www.aichengxu.com/view/31025 1.如果LinearLayout中使用Android:layout_marginRight不起作用,通过测试原来在android ...

  9. android addJavascriptInterface 不能生效 解决办法

    2015-03-10 16:47:31|  分类: 软件技术|举报|字号 订阅     下载LOFTER客户端     1. webview.addJavascriptInterface() doen ...

随机推荐

  1. 反编译.net dll

    自己公司的程序,年代久了,没有源代码,修改一些小地方,只能反编译,还好当时没有混淆. 先ildasm 反编译. 删除   .publickey = ( ) 这段,去原来签名. 然后再用找要改的IL,这 ...

  2. knockout 绑定 jquery ui datepicker (转)

    ko.bindingHandlers.datepicker = { init: function(element, valueAccessor, allBindingsAccessor) { //in ...

  3. nopcommerce商城系统--源代码结构和架构

    这个文档是让开发者了解nopcommerce解决方案结构的指南.这是新的nopcommerce开发者学习nopcommerce代码的相关文档.首先,nopCommerce源代码是很容易得到的.它是一个 ...

  4. Jquery AutoComplete的使用方法实例

    jquery.autocomplete详解 语法: autocomplete(urlor data, [options] ) 参数: url or data:数组或者url [options]:可选项 ...

  5. HDU 5007 Post Robot

    Post Robot Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  6. NGINX(七)分段下载

    前言 nginx分段下载通过ngx_http_range_filter_module模块进行处理,关于HTTP分段下载过程,可以参考HTTP分段下载一文,主要分为一次请求一段和一次请求多段 涉及数据结 ...

  7. CentOS 6.4利用xampp安装bugfree3

    1.下载xampp 安装 http://www.apachefriends.org/zh_cn/xampp.html 直接执行.run文件安装  默认会安装到/opt/lampp 2 .启动xampp ...

  8. 【暑假】[深入动态规划]UVAlive 3983 Robotruck

     UVAlive 3983 Robotruck 题目: Robotruck   Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format ...

  9. JavaScript中值的真真假假(true and false)

    值为flase的有: false 0 "" //空串 null undefined NaN 除了以上的之外的都是ture,包括"0" (zero in quot ...

  10. HW6.6

    public class Solution { public static void main(String[] args) { int[] prime = new int[50]; prime[0] ...