是否有可能动态设置背景图像?!
我试着解释一下我的意思.
String picVariable = getPictureFromServer();
ImageView image = (ImageView)v.findViewById(R.id.dynamic_image);
// I know, that doesn't work, but that's the way I looking for
image.setBackgroundResource(picVariable);
Run Code Online (Sandbox Code Playgroud)
先感谢您,
穆尔
PS.我也读过这篇文章.在一个答案中,它会建议使用java反射按名称获取R类的字段.但我以前从未使用过反射.一个例子非常有用
有时我会花更多的时间来搜索:)
我找到了解读这篇文章的答案,它对我来说很好用:
// The server says, it should be *.png
String picName = getPictureFromServer();
picName = picName.replace(".png", "");
Resources r = getResources();
int picId = r.getIdentifier(picName, "drawable", "com.mypackage.myapp");
ImageView image = (ImageView)v.findViewById(R.id.dynamic_image);
image.setBackgroundResource(picId);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10645 次 |
| 最近记录: |