2016-05-17 165 views
1

我想设置图像资源与弦乐无法解决方法setCompoundDrawablesWithIntrinsicBounds

我有设置setCompoundDrawablesWithIntrinsicBounds的问题,它不断告诉我

cannot resolve method setCompoundDrawablesWithIntrinsicBounds(android.graphics.drawable.Drawable, 0, 0, 0); 

我已经通过网上查,甚至在计算器,我的实现似乎是正确的,但我无法编译。

String uri = "drawable/my_drawable_image"; 
int imageResource = getResources().getIdentifier(uri, null, getActivity().getPackageName()); 
Drawable image = getResources().getDrawable(imageResource); 
myTextView.setCompoundDrawablesWithIntrinsicBounds(image, 0 ,0 , 0); 

请问我在做什么错?

回答

1

Drawable是一个对象。如果使用setCompoundDrawablesWithIntrinsicBounds的重载版本,该版本需要四个Drawable,则不能将0用于未使用/默认值,但必须通过null。更改

myTextView.setCompoundDrawablesWithIntrinsicBounds(image, 0 ,0 , 0); 

myTextView.setCompoundDrawablesWithIntrinsicBounds(image, null , null , null); 

没有版本的setCompoundDrawablesWithIntrinsicBounds接受一个Drawable作为第一个参数和三个int秒。有

setCompoundDrawablesWithIntrinsicBounds (int, int, int, int);以及。在这种情况下,您的代码将会改变,如

myTextView.setCompoundDrawablesWithIntrinsicBounds(imageResource, 0 ,0 , 0); 
+0

谢谢! .... –

+0

不客气 – Blackbelt