选择没有正确设置图片 [英] selector not properly set the image

查看:188
本文介绍了选择没有正确设置图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个图像来显示它有两个不同的状态,正常和presses。
图像pressed状态略有比正常状态下更多更大的规模。

问题:当我pressing它改变了形象,但它不会改变的ImageView它融为一体presses我的图像的大小和显示图像我有相同的大小在正常状态下的图像。
我已经给宽度和高度wrap_conten在我的XML文件中。

这是我的选择类,其refernce我给于的ImageView的src属性。

 <选择的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
     <! - pressed - >
    <项目机器人:可绘制=@绘制/ selected_add_item_480机器人:STATE_ pressed =真
        />
    <! - 集中 - >
    <项目机器人:可绘制=@绘制/ home_add_item_480机器人:state_focused =真/>
    <! - 默认 - >
    <项目机器人:可绘制=@绘制/ home_add_item_480/>
    < /选择>


解决方案

的布局没有得到重新测量这是问题的原因。一个简单的解决方案是创建相同的大小(像素)只有一个比另一个宽透明边界的两个图像。所以实质上的图像的可见部分将在大小不同。

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>

解决方案

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.

这篇关于选择没有正确设置图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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