Android 淡入错误
大家好 我的这段代码有问题。我正在尝试使图像淡入。这是 eclipse 错误:
The method loadAnimation(Context, int) in the type AnimationUtils is not applicable for the arguments (new Runnable(){}, int)
这是我的代码:
Handler timerHandler = new Handler();
{
Runnable loadImg2 = new Runnable() {
public void run() {
DisplayTitle(gCursor);
Bitmap bitmap2 = BitmapFactory.decodeFile(sdcard/image.jpg);
myImageView=(ImageView)findViewById(R.id.imageview1);
(ImageView)findViewById(R.id.myImageView);
Animation myFadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.fadein);
myImageView.startAnimation(myFadeInAnimation);
myImageView.setImageBitmap(bitmap2);
timerHandler.postDelayed(clearImg, 55000);//55000);
");
}
};
Hi to all
I'm having a problem with this code. I'm trying to make the image fade-in. This is the eclipse error:
The method loadAnimation(Context, int) in the type AnimationUtils is not applicable for the arguments (new Runnable(){}, int)
This is my code:
Handler timerHandler = new Handler();
{
Runnable loadImg2 = new Runnable() {
public void run() {
DisplayTitle(gCursor);
Bitmap bitmap2 = BitmapFactory.decodeFile(sdcard/image.jpg);
myImageView=(ImageView)findViewById(R.id.imageview1);
(ImageView)findViewById(R.id.myImageView);
Animation myFadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.fadein);
myImageView.startAnimation(myFadeInAnimation);
myImageView.setImageBitmap(bitmap2);
timerHandler.postDelayed(clearImg, 55000);//55000);
");
}
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试下面的代码,它对我有用......
相反
也许它会帮助你......
Try following code, it works for me....
instead
maybe it will help you...
这是一个范围问题。
目前尚不清楚您试图通过将动画创建放入 Runnable 中来做什么,但在回答您的问题时,构建失败的原因是 loadAnimation() 调用中的“this”参数引用了您正在调用的 Runnable 对象来自内部的功能。还有其他方法可以引用您所在方法内的外部对象。例如,如果外部方法位于名为 Foo 的类上,则您可以说“Foo.this”来引用 那个 实例,而不是此代码所在的 Runnable 实例。
It's a matter of scope.
It's not clear what your trying to do by putting your animation creation inside the Runnable, but in answer to your question the reason for the build failure is that the 'this' parameter in your loadAnimation() call refers to the Runnable object you are calling the function from within. There are other ways to refer to the outer object whose method you are within. For example, if the outer method is on a class called Foo, then you can say 'Foo.this' to refer to that instance instead of the Runnable instance this code is within.