selector not properly set the image

99封情书 提交于 2019-12-11 15:11:36

问题


i have two images to show it for two different state ,normal and presses. Image for pressed state is slight more bigger in size than in normal state.

problem:when i am pressing it changes the image but it wont change the size of the imageview it compresses my image and show me image with same size as image in normal state. I have given wrap_conten for width and height in my xml file.

this is my selector class whose refernce i am giving in imageview's src property.

  <selector xmlns:android="http://schemas.android.com/apk/res/android">
     <!-- pressed -->
    <item android:drawable="@drawable/selected_add_item_480" android:state_pressed="true"
        />
    <!-- focused -->
    <item android:drawable="@drawable/home_add_item_480" android:state_focused="true" />
    <!-- default -->
    <item android:drawable="@drawable/home_add_item_480"/>
    </selector>

回答1:


The layout is not getting re-measured which is the cause of the problem. A simple solution would be to create both the images of same size (pixels) but one with wider transparent border than the other. So essentially the visible portion of the images will differ in size.



来源:https://stackoverflow.com/questions/15087926/selector-not-properly-set-the-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!