2012-05-02 17 views
1
私は私の画面は次のように点滅して作ってみる

点滅に関する相談:アンドロイド:画面

for (int i=0;i<10;i++) 
     { 
      targetView.setBackgroundColor(Color.BLUE); 
      for (int j=0;j<500;j++); //delay 
      targetView.setBackgroundColor(Color.RED); 
     } 

が、それは文句を言わない

答えて

3

はこれを試してみてください作業を、

targetView.setBackgroundColor(Color.BLUE); 
try { 
      Thread.sleep(5000); // milliseconds to wait... 
     } catch (InterruptedException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
targetView.setBackgroundColor(Color.RED); 

EDIT

public class TSActivity extends Activity { 


    LinearLayout lin; 
    private int finalStatus = 0; 
    private Handler colorHandler = new Handler(); 
    boolean flag = false; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     lin = (LinearLayout)findViewById(R.id.linMain); 

      new Thread(new Runnable() { 
       public void run() { 
        while (finalStatus < 100) { 

         // process some tasks 
         finalStatus = doSomeTasks(); 

         try { 
          Thread.sleep(500); 
         } catch (InterruptedException e) { 
          e.printStackTrace(); 
         } 

         // Update the color 
         colorHandler.post(new Runnable() { 
          public void run() { 
           if(flag) 
           { 
           lin.setBackgroundColor(Color.BLUE); 
           flag = false; 
           } 
           else 
           { 
            lin.setBackgroundColor(Color.GREEN); 
            flag = true; 
           } 
          } 
         }); 
        } 

       } 
      }).start(); 
    } 

// color changer simulator... a really simple 
    public int doSomeTasks() { 

     long fileSize = 0; 

     while (fileSize <= 1000000) { 

      fileSize++; 

      if (fileSize == 100000) { 
       return 10; 
      } else if (fileSize == 200000) { 
       return 20; 
      } else if (fileSize == 300000) { 
       return 30; 
      } 
      // ...add your own 
      } 

     return 100; 
    } 
} 
これはあなたを助ける10

・ホープ..

おかげで...あなたはまた、ハンドラを使用することができます

+0

助けてくれてありがとう、私はこれを試してください - それは文句を言わない私のEDIT – Gali

+0

に動作します!!!その作品!!! –

+0

感謝を参照してください@Gali – Gali

0

Runnable r=new Runnable(){ 
    public void run(){ 
     if(red){ 
      targetView.setBackgroundColor(Color.RED); 
      red=false; 
     } 
     else{ 
      targetView.setBackgroundColor(Color.BLUE); 
      red=true; 
     } 
     if(!stop_blinking) handler.postDelayed(this,1000); 

    } 
}; 

handler=new Handler(); 
handler.postDelayed(r,1000); //1000 is in mili secs. 

stop_blinkingはあなたが表示の点滅が停止するたびに設定する必要があるブール値です。

+0

助けてくれてありがとう、私はこれを試してみる - しかし、それは動作しません – Gali

関連する問題