我目前正在尝试在ImageView中播放动画。
此代码工作正常:
//Run Animations
ImageView char1 = (ImageView) findViewById(R.id.char1);
//set the animation drawable as background
char1.setBackgroundResource(R.anim.male03idle);
//create an animation drawable using the background
AnimationDrawable char1anim = (AnimationDrawable) char1.getBackground();
//start the animation
char1anim.start();
我想在R.anim中使用String指向这个动画。
例如:
String char1resource = "male" + "03" + "idle";
然后在char1.setBackgroundResource中使用char1resource。
我尝试过这样的事情,但它不起作用:
String c1r = "male" + "03" + "idle";
int char1Resource = getResources().getIdentifier(c1r, null, getPackageName());
Drawable image = getResources().getDrawable(char1Resource);
//Run Animations
ImageView char1 = (ImageView) findViewById(R.id.char1);
//set the animation drawable as background
char1.setBackgroundResource(image);
//create an animation drawable using the background
AnimationDrawable char1anim = (AnimationDrawable) char1.getBackground();
//start the animation
char1anim.start();
答案 0 :(得分:0)
好的,问题是我没有声明源位置。
“anim /”+“male”+“03”+“idle”