Android 淡入错误

发布于 2024-11-05 12:35:02 字数 835 浏览 1 评论 0原文

大家好 我的这段代码有问题。我正在尝试使图像淡入。这是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

箹锭⒈辈孓 2024-11-12 12:35:02

尝试下面的代码,它对我有用......

Animation myFadeInAnimation =
    AnimationUtils.loadAnimation(getapplicationContext, R.anim.fadein);

相反

Animation myFadeInAnimation =
    AnimationUtils.loadAnimation(this, R.anim.fadein);

也许它会帮助你......

Try following code, it works for me....

Animation myFadeInAnimation =
    AnimationUtils.loadAnimation(getapplicationContext, R.anim.fadein);

instead

Animation myFadeInAnimation =
    AnimationUtils.loadAnimation(this, R.anim.fadein);

maybe it will help you...

高冷爸爸 2024-11-12 12:35:02

这是一个范围问题。

目前尚不清楚您试图通过将动画创建放入 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文