Android ImageView选择器不起作用

这是我的选择器:

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

    <item android:drawable="@drawable/white_small_down_arrow_v4"   android:state_pressed="true"/>  
    <item android:drawable="@drawable/white_small_up_arrow_v4" android:state_focused="false"/> 
    <item android:drawable="@drawable/white_small_up_arrow_v4" /> <!-- default -->

</selector>

这就是我在ImageView上应用它的方式:

     <ImageView
            android:id="@+id/change_city_small_down_ImageView"
            android:clickable="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_toRightOf="@+id/changeCityRelativeLayout"
            android:layout_marginLeft="5dp"
            android:background="@drawable/change_city_selector"
   </ImageView>

现在的问题是,当我按下ImageView时,相应的状态可绘制图像不会更改.我试过其他的wigdet,也行不通.我不知道为什么,因为我曾经以相同的方式做这件事,并且它起作用了.

单击它时,我已监视imageview状态.

v.hasFocus():false,v.isClickable():true,v.isInTouchMode():true,v.isEnabled():true,v.ispressed():true

我犯了一个严重的错误,white_small_down_arrow_v4和white_small_up_arrow_v4实际上指向相同的方向,换句话说,它们是同一张图片.

因此,如果他们发现选择器不起作用,我的错误可能会帮助其他人,并且要做的第一件事是检查状态可绘制对象是否相同.

解决方法:

试试这个:使用图片android:src =“ @ drawable / change_city_selector”代替android:background =“ @ drawable / change_city_selector”

<ImageView
        android:id="@+id/change_city_small_down_ImageView"
        android:clickable="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@+id/changeCityRelativeLayout"
        android:layout_marginLeft="5dp"
        android:src="@drawable/change_city_selector"
</ImageView>

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...