jul*_*jul 1 resources android drawable
如何在BitmapDrawable
构造函数中设置资源?在下面的示例中,我想将资源设置R.drawable.default_fb_pic
为ID,而不是资源.我怎样才能获得资源?随着ImageView
我们可以设置其ID的资源:
imageview.setImageResource(R.drawable.whatever);
Run Code Online (Sandbox Code Playgroud)
我不清楚为什么有时可以使用其ID直接设置资源,有时不能.
有人可以帮忙吗?
static class DownloadedDrawable extends BitmapDrawable {
public DownloadedDrawable(BitmapDownloaderTask bitmapDownloaderTask) {
super(R.drawable.default_fb_pic); //"The constructor BitmapDrawable(int)
//is undefined",
//which I understand because it takes a resource.
//But how do I get the resource and why is there no constructor
//directly with the id?
}
...
}
Run Code Online (Sandbox Code Playgroud)
有
Context.getResources()
Run Code Online (Sandbox Code Playgroud)
http://developer.android.com/reference/android/content/Context.html#getResources()
你可以把它链接起来
getDrawable()
Run Code Online (Sandbox Code Playgroud)
http://developer.android.com/reference/android/content/res/Resources.html#getDrawable(int)
mContext.getResources().getDrawable(R.drawable.default_fb_pic);
Run Code Online (Sandbox Code Playgroud)
您只需要引用您的上下文.
归档时间: |
|
查看次数: |
6118 次 |
最近记录: |