2012-04-09 76 views
0

我試圖動畫圖像,這是我在XML文件中與動畫圖像,取代從OnCreat功能代碼setOnClickListener功能

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
android:oneshot="false" > 
<item android:drawable="@drawable/father11" android:duration="200" /> 
<item android:drawable="@drawable/father22" android:duration="200" /> 
<item android:drawable="@drawable/father33" android:duration="200" /> 
<item android:drawable="@drawable/father44" android:duration="200" /> 
<item android:drawable="@drawable/father55" android:duration="200" /> 
</animation-list> 

,但在我的應用程序的代碼,我跑動畫圖像時,按鈕按下,但我得到sentax錯誤

btn_father.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      SignImage = (ImageView) findViewById(R.id.Sign); 
      SignImage.setImageResource(R.drawable.fatherr); 
      lightsAnimation=(AnimationDrawable) SignImage.getDrawable(); 

      } 
     public void onWindowFocusChanged(boolean hasFocus) { 
       super.onWindowFocusChanged(hasFocus); 
       lightsAnimation.start(); 

      } 


    }); 

我的鏈接閱讀本sentece但沒有理解它「(如果可以很容易地已經開始按鈕或其他類型的輸入),在更換主類在這個類的src樹中的main.java文件「

+0

是的,它可以很容易地啓動一個按鈕或其他類型的輸入,請粘貼您的logcat得到實際問題 – jeet 2012-04-09 04:40:06

+0

你是什麼意思「你的logcat」? – Nada 2012-04-09 11:29:16

+0

你得到了異常,所以粘貼在這裏的位置 – jeet 2012-04-09 11:31:50

回答

0

好吧,View.OnClickListener只有一個方法的onClick,所以如果你想在點擊開始動畫然後執行以下操作:

btn_father.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      SignImage = (ImageView) findViewById(R.id.Sign); 
      SignImage.setImageResource(R.drawable.fatherr); 
      lightsAnimation=(AnimationDrawable) SignImage.getDrawable(); 
      lightsAnimation.start(); 

      } 


    }); 

如果您想對焦點改變將被應用的動畫過,然後在View上應用onFocusChanged偵聽器。

+0

thnxxxxxx,即時通訊只是尖叫現在,我做了你發佈,把Stat函數內OnClick,然後把onWindowFocusChanged在類錯誤地說,我確實把功能放在另一個哈哈里面 – Nada 2012-04-09 12:34:39