android gridview按钮边框和定制点击颜色

android gridview按钮边框和定制点击颜色
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/gridview"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:numColumns="2"
          android:verticalSpacing="2dp"
          android:horizontalSpacing="2dp"
          android:stretchMode="columnWidth"
          android:gravity="center"
          android:background="#11000000" 
          android:listSelector="@drawable/grid_view_item_selector_xml"
        />
android gridview按钮边框和定制点击颜色

 

gridView的布局文件:grid_view_item.xml

android gridview按钮边框和定制点击颜色
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_height="wrap_content"
        android:paddingBottom="2dip"
        android:layout_width="fill_parent"
        android:background="@drawable/grid_view_item_selector_xml"
        >

    <ImageView
            android:layout_height="wrap_content"
            android:id="@+id/ItemImage"
            android:layout_width="wrap_content"
            android:layout_centerHorizontal="true">
    </ImageView>

    <TextView
            android:layout_width="wrap_content"
            android:layout_below="@id/ItemImage"
            android:layout_height="wrap_content"
            android:text="TextView01"
            android:layout_centerHorizontal="true"
            android:id="@+id/ItemText">
    </TextView>
</RelativeLayout>  
android gridview按钮边框和定制点击颜色

 

 

grid_view_item_selector_xml.xml

android gridview按钮边框和定制点击颜色
<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true" android:drawable="@drawable/grid_view_item_press_shape"/>

    <item android:drawable="@drawable/grid_view_item_shape"/>
</selector>
android gridview按钮边框和定制点击颜色

 

grid_view_item_press_shape.xml

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#5500ffff"/>
</shape>

 

grid_view_item_shape.xml

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#fff"/>
</shape>

 

注意:在gridView组件中要声明listSelector来覆盖原有的点击颜色效果,还有在gridView中声明该item的背景颜色。

android gridview按钮边框和定制点击颜色

上一篇:关于iphone中微信无法调用百度api的解决方案


下一篇:安卓开发环境搭建