我想我越来越近但仍然遇到资源错误.我在所有3个可绘制文件夹中都有一个名为rock.png的图像文件.
在我的布局MAIN.XML中:
<ImageView android:id="@+id/rockId" android:src="@drawable/rock"></ImageView>
Run Code Online (Sandbox Code Playgroud)
在我的代码中:
int resID = getResources().getIdentifier("rockId" , "id", "com.testing");
ImageView image = (ImageView) findViewById(resID);
Run Code Online (Sandbox Code Playgroud)
我仍然在我的错误catlog中看到这个:
10-30 17:36:24.485: WARN/ResourceType(74): Resources don't contain package for resource number 0x7f020000
Run Code Online (Sandbox Code Playgroud)
关于我可能做错什么的任何想法?欢迎任何提示
Ped*_*nho 24
找到控件:
ImageView image = (ImageView) findViewById(R.id.rockId);
Run Code Online (Sandbox Code Playgroud)
要从drawable动态加载图像我使用此功能
public static int getDrawable(Context context, String name)
{
Assert.assertNotNull(context);
Assert.assertNotNull(name);
return context.getResources().getIdentifier(name,
"drawable", context.getPackageName());
}
Run Code Online (Sandbox Code Playgroud)
这将返回你的drawable的id,现在你需要的是在控件中设置图像:
image.setImageResource(int Id);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14173 次 |
| 最近记录: |