使用<selector>风格化Android的GridView元素背景

 在布局文件home.xml中有下面的代码:

    <GridView android:id="@+id/all_apps"
        android:background="@drawable/application_background"
        android:persistentDrawingCache="animation|scrolling"
        android:alwaysDrawnWithCache="true"
        android:scrollbars="none"
        android:drawSelectorOnTop="false"
        android:listSelector="@drawable/grid_selector"
        android:numColumns="auto_fit"
        android:columnWidth="78dp"
        android:stretchMode="spacingWidth"
        android:layout_weight="1.0"
        android:layout_height="0dip"
        android:layout_width="match_parent"
        android:stackFromBottom="true"
        android:visibility="invisible" 
    />
    在GridView属性中注意上面绿色的那一行.它指定了元素的背景布局文件为dwawable目录下面的grid_selector.xml文件.打开grid_selector.xml文件,有下面的描述:

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

            android:drawable="@drawable/pressed_application_background_static" />
        <item android:state_window_focused="false"  

             android:drawable="@drawable/focused_application_background_static" />
        <item android:state_window_focused="true" 

              android:drawable="@drawable/focused_application_background_static" />
    </selector>

    在此文件中,三个<item>分别指定了在点击图标,聚焦,失焦的情况下使用的元素背景

    其中,在dwawable-hdpi目录下的有上面说提到的片,.我们通过这样的方法就可以改变其大小,形状以及颜色了,这会使你的GridView制作得更漂亮.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值