【发布时间】:2016-09-07 22:11:41
【问题描述】:
这是我的选择器:
<?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 实际上指向同一个方向,换句话说,它们是同一张图片。
所以,如果他们发现选择器不起作用,可能我的错误会帮助其他人,首先要做的是检查状态可绘制对象是否相同......
【问题讨论】:
-
这是 imageview 附加的布局:
-
试试 android:src="@drawable/change_city_selector" 而不是 android:background="@drawable/change_city_selector" @Qin
-
@Indiandroid 不行,拼命尝试各种状态组合
标签: android android-imageview android-selector