2014-07-09 54 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!這更有意義。完美工作 –