2012-03-28 108 views
0

圓形旋轉onTouch只有在點擊一次後才起作用,它什麼都不做。圓形旋轉onTouch

這裏是我的代碼:

setOnTouchListener(new OnTouchListener() { 

     public boolean onTouch(View v, MotionEvent event) { 
      int n = 0; 
      postInvalidate(); 
      for(int i=0; i<360; i++){ 
       setRotationX(n + 1); 
      } 
      forceLayout(); 

我希望有人能幫助我。 我如何查看代碼以便它可以多次運行?

+0

觸摸後纔開始動畫並不容易嗎? – goodm 2012-03-28 09:41:54

+0

thanx的評論,但我怎麼能讓這樣的動畫? – user1297720 2012-03-28 09:49:38

回答

3

如果使用goodm解決方案,您應該在您的清單中添加以下內容:

<supports-screens android:resizeable="true" 
        android:smallScreens="true" 
        android:normalScreens="true" 
        android:largeScreens="true" 
        android:anyDensity="true"/> 

這是用於ICS和ICS之前的版本。

+1

有什麼新東西,ICS有多少新東西? – goodm 2012-03-28 10:12:09

+0

我只知道,使用該代碼,所有動畫和祝詞均可正常工作。 – fr4n 2012-03-28 10:16:59

+1

好的,謝謝..... – goodm 2012-03-28 10:53:48

1

做動畫,你需要創建在res文件夾中的文件夾「動畫」,並添加這樣一個XML文件:在您的Java類的嘗試

<?xml version="1.0" encoding="UTF-8"?> 
<rotate xmlns:android="http://schemas.android.com/apk/res/android" 
    android:fromDegrees="0" 
    android:toDegrees="360" 
    android:pivotX="50%" 
    android:pivotY="50%" 
    android:duration="1000"/> 

Animation a = AnimationUtils.loadAnimation(this, R.anim.yourAnim); 
a.setAnimationListener(new AnimationListener() 
{ 
    @Override 
    public void onAnimationEnd(Animation animation) 
    { 
     animPlaying = false; 
    } 

    @Override 
    public void onAnimationStart(Animation animation) 
    { 
     animPlaying = true; 
    } 

    @Override 
    public void onAnimationRepeat(Animation animation){} 
}); 

public boolean onTouch(View v, MotionEvent event) 
{ 
     int n = 0; 
     postInvalidate(); 
     if(aninmPlaying == false) 
     { 
      yourView.startAnimation(a); 
     } 
     forceLayout();