2014-03-12 78 views
0

我正在嘗試使圖像從左到右,從右到左移動。這是我的代碼有:令牌上的語法錯誤

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行似乎一切都還好

回答

0

此代碼現在

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 animation)來解決這個問題,以保存設置動畫屬性的代碼,現在它編譯並運行正常,但我不知道您的預期輸出是什麼。

希望這會有所幫助

相關問題