Animation 令牌上的语法错误

Animation 令牌上的语法错误,animation,syntax,imageview,token,Animation,Syntax,Imageview,Token,我试着让图像从左到右,从右到左移动。这是我的代码: package com.example.; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.animation.TranslateAnimation; import android.widget.ImageView; public class PlayActivity extends

我试着让图像从左到右,从右到左移动。这是我的代码:

    package com.example.;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
public class PlayActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_play);
}
ImageView imageView2 = (ImageView) findViewById(R.id.imageView2);

  TranslateAnimation animation = new TranslateAnimation(0.0f, 400.0f,
    0.0f, 0.0f);
  animation.setDuration(5000);
  animation.setRepeatCount(5);
  animation.setRepeatMode(2);
  animation.setFillAfter(true);
  imageView2.startAnimation(animation);
但是,在最后5行中,它给出了以下错误:

Multiple markers at this line
    - Syntax error on token(s), misplaced 
     construct(s)
    - Syntax error on token "5000", delete this 
     token
Multiple markers at this line
    - Syntax error on token "5", delete this 
     token
    - Syntax error on token(s), misplaced 
Multiple markers at this line
    - Syntax error on token(s), misplaced 
     construct(s)
    - Syntax error on token "2", delete this 
     token
Multiple markers at this line
    - Syntax error on token "true", delete this 
     token
    - Syntax error on token(s), misplaced 
Multiple markers at this line
    - Syntax error on token(s), misplaced construct(s)
    - Syntax error on token "animation", VariableDeclaratorId expected after 
     this token

谁能告诉我该修什么?除了这5行代码之外,一切似乎都很好

这段代码现在适合我了

    package com.example.;

    import android.os.Bundle;
    import android.app.Activity;
    import android.view.Menu;
    import android.view.animation.TranslateAnimation;
    import android.widget.ImageView;
    public class PlayActivity extends Activity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_play);
        }
        ImageView imageView2 = (ImageView) findViewById(R.id.imageView2);

        TranslateAnimation animation = new TranslateAnimation(0.0f, 400.0f,
                0.0f, 0.0f);
        protected TranslateAnimation setanimation(TranslateAnimation animation)
        {
            animation.setDuration(5000);
            animation.setRepeatCount(5);
            animation.setRepeatMode(2);
            animation.setFillAfter(true);
            imageView2.startAnimation(animation);
            return animation;
        }

}
问题是您试图在函数体之外设置动画属性的位置。因此,我通过创建函数
protected TranslateAnimation setanimation(TranslateAnimation)
将代码保存在设置动画属性的位置来修复它,现在它可以正常编译和运行,尽管我不知道您期望的输出是什么

希望这有帮助