1

Upon all the research I could do on the Internet, it seems as though accessing a resource (.xml layout file, in my case), located in the /res/drawable folder to return as Drawable was as simple as calling this line:

Ruboto::R::drawable::stroke_bg

However, when I tried that, I received the following error:

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

The line on my view is:

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

What is it that I am missing to get the resource out of that folder?

4

1 回答 1

1

Ruboto::R::drawable::stroke_bg不是 Drawable,而是int资源 ID。您必须获取实际资源才能将其用作 Drawable。将背景属性更改为如下所示:

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

或者

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

于 2014-07-09T23:01:04.160 回答