开发者

android fade-in error

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);
        myImageVie开发者_Python百科w.setImageBitmap(bitmap2);
        timerHandler.postDelayed(clearImg, 55000);//55000);
        "); 
    }  
};


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...


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜