在使用 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. [Mac][phpMyAdmin] [2002] No such file or directory

    我从phpMyAdmin的官网下载了最新版,将它解压到 /Library/WebServer/Documents 下,然后把文件夹改名 phpmyadmin . 接着输入在浏览器中输入 localho ...

  2. Oracle 10g DataGuard手记之基础配置

    DataGuard为企业数据的高可用性,数据安全以及灾难恢复提供支持,一般由一个primary db与几个物理或逻辑standby db组成一个DataGuard配置. 系统环境 操作系统为windo ...

  3. ARM Linux 如何--注册和触发--软中断

    1. 注册软中断当然是通过open_softirq 例子如下: void __init init_timers(void) { int err = timer_cpu_notify(&time ...

  4. Hapoop原理及MapReduce原理分析

    Hapoop原理 Hadoop是一个开源的可运行于大规模集群上的分布式并行编程框架,其最核心的设计包括:MapReduce和HDFS.基于 Hadoop,你可以轻松地编写可处理海量数据的分布式并行程序 ...

  5. 时间管理(GTD)

    今天中午看了30分钟老王讲战胜拖延症和时间管理  视频地址:多呗课堂 贴两个总结的图在此: 计划中使用的四象限法和十八分钟法很好. 今年多研究研究,实践一下Geting Things Done.

  6. javascript活动对象的理解——伪单例模式

    在自己研究javascript各种设计模式的过程中,偶然写出的一段代码让自己理解的更深刻了,之所以称之为伪单例模式,是因为这段代码造成的结果很想单例模式,但是实际上是活动对象捣乱所造成的误会. 代码很 ...

  7. algorithm@ Strongly Connected Component

    Strongly Connected Components A directed graph is strongly connected if there is a path between all ...

  8. leetcode@ [49] Group Anagrams (Hashtable)

    https://leetcode.com/problems/anagrams/ Given an array of strings, group anagrams together. For exam ...

  9. Spring基础知识汇总 Java开发必看

    Spring简介 Spring框架由Rod Johnson开发,2004年发布了Spring框架的第一版.Spring是一个从实际开发中抽取出来的框架,因此它完成了大量开发中的通用步骤,留给开发者的仅 ...

  10. 解决Visual Studio 2013调试时 Web服务框架中出现了无法识别的错误 问题

    此问题出现过很多次,点帮助,google, baidu 都没解决,后经过摸索解决,记录下来1.查找80port是否有被占用情况,需要查看skype[这东西不知道为什么为占用80], Reporting ...