2014-07-09 56 views
1

在我可以在Internet上进行的所有研究中,似乎访问位于/ res/drawable文件夹中的资源(在我的情况下为.xml布局文件)以回报绘制对象是因调用该行简单:访问Ruboto中的/ res/drawable文件夹

Ruboto::R::drawable::stroke_bg 

然而,当我尝试了,我收到以下错误:

could not coerce Fixnum to class android.graphics.drawable.Drawable 

对我的看法行是:

scroll_view :background => Ruboto::R::drawable::stroke_bg, :layout => { :width => :match_parent, height: 1000 } 

这是什么,我想丢失该资源的文件夹?

回答

1

Ruboto::R::drawable::stroke_bg不是可绘制的,而是int资源ID。您必须获得实际资源才能将其用作Drawable。 background属性更改为这样的事情:

background: resources.getDrawable(Ruboto::R::drawable::stroke_bg)

background: resources.getDrawable($package.R.drawable.stroke_bg)

+0

谢谢,@donV!这更有意义。完美工作 –