动画刷新图标

时间:2014-09-25 03:31:58

标签: android animation refresh android-animation

计划是刷新图标在用户点击刷新图标时开始制作动画,但是,当我实现动画功能时似乎有错误; " AnimationUtils类型中的方法loadAnimation(Context,int)不适用于参数(new View.OnClickListener(){},int)"。

以下是代码段。如何在保留onClickListener框架的同时从动画源加载动画,而不会出现上述错误。

    final ImageView refreshBtn= (ImageView) findViewById(R.id.spin_refresh);
    Log.i("RootActivity:setupHeader","******ImageView refreshBtn******");
    //Listening to Button Click by User
    refreshBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            //To set new INTENT on calling Methods in UPDATE & DOWNLOADSERVICE 
            .....

            //Perform Refresh Animation
            LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            ImageView iv = (ImageView)inflater.inflate(R.layout.header, null);

            //ISSUE IS AT .loadAnimation not able to be implemented.
            Animation rotation = AnimationUtils.loadAnimation(this, R.anim.rotate_refresh);
            rotation.setRepeatCount(Animation.INFINITE);
            iv.startAnimation(rotation);
            item.setActionView(iv);

            //ALERT DIALOG TO INFORM USER THAT REFRESH FUNCTION HAS BEEN CALLED
            .......
        }
    });       

2 个答案:

答案 0 :(得分:0)

更改

Animation rotation = AnimationUtils.loadAnimation(this, R.anim.rotate_refresh);

Animation rotation = AnimationUtils.loadAnimation(YourActivity.this, R.anim.rotate_refresh);

原因是,在您的代码中,this指的是View.OnClickListener,而不是您的活动。

答案 1 :(得分:0)

这指的是OnclickListener 将其更改为您的上下文

Animation rotation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotate_refresh);