zoukankan      html  css  js  c++  java
  • Android GridView 添加 网格线解决办法

    在使用 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.   
    8.     <TextView  
    9.         android:id="@+id/tv_category_name"  
    10.         android:layout_width="wrap_content"  
    11.         android:layout_height="wrap_content"  
    12.         android:layout_centerInParent="true"  
    13.         android:textColor="@color/yulore_black"  
    14.         android:text="合租房"  
    15.         android:textSize="18sp"   
    16.         android:singleLine="true"  
    17.         android:padding="15dp"/>  
    18.   
    19. </RelativeLayout>  

     

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

     

  • 相关阅读:
    为aptget设置http代理[转]
    tty&pty
    Overfencing
    ubuntu修改runlevel
    ls l文件类型[转]
    ubuntu文字界面与图形界面切换
    ubuntu没有/etc/inittab文件
    linux一些缩写的意思
    redhat server 5.4安装中文
    关闭linux警报
  • 原文地址:https://www.cnblogs.com/Free-Thinker/p/3591669.html
Copyright © 2011-2022 走看看