StateListDrawable的使用

StateListDrawable对应selector标签,每个Drawable对应着View的一种状态,系统会根据View的状态选择合适的drawable

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
          android:constantSize="false"
          android:dither="true"
          android:variablePadding="false">

    <item android:drawable="@mipmap/picture"
          android:state_pressed="true"
          android:state_focused="true"
          android:state_hovered="true"
          android:state_selected="true"
          android:state_checkable="true"
          android:state_checked="true"
          android:state_enabled="true"
          android:state_activated="true"
          android:state_window_focused="true"/>
</selector>

android:constantSize=”false”——StateListDrawable的大小是否不随着其状态的改变而改变,一般情况下为fasle

android:dither=”true”——是否开启抖动效果,默认为true

android:variablePadding=”false”——StateListDrawable的padding表示是否随着其状态的改变而改变,默认为false

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
          android:constantSize="false"
          android:dither="true"
          android:variablePadding="false">

    <!--按下的状态-->
    <item android:drawable="@mipmap/picture"
          android:state_pressed="true"/>
    <!--获取焦点的状态-->
    <item android:drawable="@mipmap/picture"
          android:state_focused="true"/>
    <!--默认状态-->
    <item android:drawable="@mipmap/picture"/>

</selector>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值