gpt4 book ai didi

Android ImageView 选择器不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 13:24:11 24 4
gpt4 key购买 nike

这是我的选择器:

<?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():假,v.isClickable():真,v.isInTouchMode():真,v.isEnabled():真,v.isPressed():真


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

所以,我的错误可能会帮助其他人,如果他们发现选择器不起作用,首先要做的是检查状态 drawables 是否相同....

最佳答案

试试这个:使用图像 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 ImageView 选择器不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22852336/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com