2012-01-25 22 views
1

我遇到了一个问题,ImageButton背景是使用与我的某个资源不同的drawable绘制的。我将背景设置为透明,但在某些情况下,它将拾取一个名为bottom_shadow.9.png的drawable。为什么为什么!?这很奇怪...ImageButton背景是自己开发的吗? Drawables wild wild?

我以前见过这个问题...我的一些应用用户抱怨看到这个问题,现在我决定解决这个问题!看看我现在有什么。任何提示或想法都会有所帮助。

我下值/ colors.xml创建的颜色值:

<color name="transparent">#00000000</color> 

我在布局下一个我XML布局的ImageButton /:

<ImageButton 
    android:id="@+id/ibHelp" 
    android:layout_width="wrap_content" 
    android:layout_height="@dimen/settings_list_item_height" 
    android:background="@color/transparent" 
    android:contentDescription="@string/content_desc_more_information" 
    android:paddingLeft="10dp" 
    android:paddingRight="10dp" 
    android:scaleType="centerInside" 
    android:src="@drawable/btn_help" /> 

这是我所看到的生成R.java文件:

public static final class drawable { 
    public static final int bottom_shadow=0x7f020000; 
} 

public static final class color { 
    public static final int transparent=0x7f080009; 
} 

这是它应该是什么样子:

enter image description here

这是我所看到的:

enter image description here

+0

有时Eclipse中的某些内容出错,我在应用程序的错误位置看到了错误的资源。在这些情况下,清理项目对我有帮助(项目 - >清洁)。 –

+0

感谢您的评论。我注意到,干净的帮助。这个问题有点糟糕......有时候没有办法重现它,而不是在某个电话上发生问题...... – Jona

回答

0

我想你想你的按钮的背景是某种颜色,但你已经分配既是src和颜色的该按钮(在布局xml中),这意味着该按钮可以使用src图片作为背景,而不是纯色。我不知道我是否明确了这一点。

+0

我不确定我是否理解你写的内容......但是声明一个src和背景是有效使用ImageButton。我没有看到Android API上的任何地方关于不使用颜色资源和可绘制资源。 – Jona

2

我认为你在另一个项目上面临同样的问题:当在背景上使用透明颜色#00000000时,Android实际上不会使其透明,而是直接在它下面使用背景可绘制元素。

不知道我刚刚说的是什么,但要检查是否是这样,我发现一个快速简单的解决方案:不要使用#00000000作为背景透明,但其他任何完全透明的颜色:#00FF0000或即使#00F00000也应该这样做。

见我在谷歌跟踪器提出了这个问题:http://code.google.com/p/android/issues/detail?id=24653

+0

感谢您的回答!我明白你说的透明价值全零。我想知道Android是否也有挑选不仅仅是直接背景下的背景,而是挑选一个随机drawable。在我的情况下,这是一个随机的drawable,甚至没有用在这个特定的片段上。 – Jona

1

你为什么要创建自己的颜色,当它建成Android.R.color?我会尝试使用:

android:background="@android:color/transparent" 

无论它是否解决了您的问题,它更简单,更清洁。

+0

感谢您的反馈...但是,无论使用什么颜色都无所谓,问题仍然会发生。 – Jona

0

我想补充这一点,我看到很奇怪的周期性显示腐败在我透明的ImageButton背景,因为我被指定为跟随我的背景选择的项目:

<item android:drawable="@android:color/transparent" android:state_focused="false" android:state_pressed="false" android:state_selected="true"/> 

威力似乎工作偶尔,但我绝对有例子,ImageButtons会渲染一个可怕的全白背景,而不是很好的透明背景。

请注意,我用颜色资源混合了android:drawable语法。指定颜色资源的正确方法似乎是android:color =“#FF00FF”属性或作为使用元素的项目的子元素。我搜索了很长时间,并且最终找到了这篇文章。