zoukankan      html  css  js  c++  java
  • 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"
            />

    gridView的布局文件:grid_view_item.xml

    <?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>  

    grid_view_item_selector_xml.xml

    <?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>

    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的背景颜色。

  • 相关阅读:
    Eclipse中的Web项目自动部署到Tomcat
    Linux之grep命令
    Linux之sort
    Python 字典中一键对应多个值
    手动下载python更新后 换回以前版本
    N个降序数组,找到最大的K个数
    蓄水池抽样算法
    空瓶子换水问题
    rand()产生随机数 及其和clock()的不同
    C++复数运算 重载
  • 原文地址:https://www.cnblogs.com/wuyou/p/3535569.html
Copyright © 2011-2022 走看看