Android开发之实现GridView支付宝九宫格

2019-12-10 19:53:19刘景俊
  • <item android:state_pressed="true"><shape android:shape="rectangle">   <stroke android:width="1.0px" android:color="@color/line" />  
  • <gradient android:angle="270.0" android:endColor="#ffe8ecef" android:startColor="#ffe8ecef" />   </shape></item>  
  • <item android:state_focused="true"><shape android:shape="rectangle">   <gradient android:angle="270.0" android:endColor="#ffe8ecef" android:startColor="#ffe8ecef" />  
  • <stroke android:width="1.0px" android:color="@color/line" />   </shape></item>  
  • <item><shape android:shape="rectangle">   <gradient android:angle="270.0" android:endColor="#ffffffff" android:startColor="#ffffffff" />  
  • <stroke android:width="1.0px" android:color="@color/line" />   </shape></item>  
  • </selector> 

    定义一个selector,在里面设置一个形状为矩形rectangle,设置这个矩形的stroke描边属性的颜色为分割线的颜色,然后在不同的state的item中设置不同的gradient渐变属性,从而实现在单个item在被点击选中时的效果。

    接着就是给我们GridView的item布局中加上背景了:

     

     
    1. <?xml version="1.0" encoding="utf-8"?>   <RelativeLayout xmlns:android="http://www.easck.com/apk/res/android" 
    2. android:layout_width="fill_parent"  android:layout_height="fill_parent"