我有这个代码:
translateRight("iv1"); //iv1 is an id of an imageView
private void translateRight(String st){
ImageView img = (ImageView)findViewById(R.id.st);
Animation a = AnimationUtils.loadAnimation(this, R.anim.translate_right);
img.startAnimation(a);
}
我有一个显示动画的方法“translateRight”,但是在这个方法中我应该传递一个资源 ID;我尝试使用字符串但它不起作用,我该怎么办?
最佳答案
资源 id - 是一个整数值。只需传递一个 int
:
private void translateRight(int resource){
ImageView img = (ImageView) findViewById(resource);
//stuff
}
关于Android:将资源ID作为参数传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12249227/