Android的ImageView的选择不工作 [英] Android ImageView selector does not work

查看:159
本文介绍了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的:

This is how I applied it on 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>

现在的问题是,当我pressed的ImageView的,按该国家绘制的图像不会改变。我已经尝试过其他的Wigdet,也不能正常工作。我想不通为什么,becasue我以前做这个同样的方式,和它的作品。

Now, the problem is, when I pressed the ImageView, the according state drawable image does not change. I have tried it on other wigdet, also not work. I can't figure out why, becasue I used to do this the same way, and it works.

我已经监测ImageView的状态被点击时。

I have monitored imageview states when it been clicked.

v.hasFocus():假的,v.isClickable():真,v.isInTouchMode():真,v.isEnabled():真的,v.is pressed():真

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实际上指向同一个方向,换句话说,它们是相同的画面。

I made a terrible mistake, the white_small_down_arrow_v4 and white_small_up_arrow_v4 actually pointing the same direction, in other words, they are same picture.

所以,可能是我的失误都会帮助别人,如果他们发现选择不工作,并且做的第一件事是检查,如果国家可绘制是相同的......

so, probably my mistake will help someone else if they found selector does not work, and first thing to do is to check if the state drawables are the same....

推荐答案

试试这个:使用图像的android:SRC =@绘制/ change_city_selector而不是的android:背景=@绘制/ change_city_selector

Try this: use image android:src="@drawable/change_city_selector" instead of 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的选择不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆