2012-02-11 6 views
9

私はカスタムレイアウトのメディアプレーヤーを設計しています。私は16秒間使用しないとインタフェースが消えてしまいます。ユーザーが画面に触れると再び表示されます。コードスニペットは以下の通りです:のonCreate(インサイドアンドロイドでメディアプレーヤーのレイアウトを自動的に隠す

public void showhideControllers(int n) { 
    if (n == 1) { 
     /* make layout invisible */ 

     Handler handler = new Handler(); 
     handler.postDelayed(new Runnable() { 
      public void run() { 
       volumeBar.setVisibility(View.INVISIBLE); 
       audioControllView.setVisibility(View.INVISIBLE); 
       topBar.setVisibility(View.INVISIBLE); 
      } 
     }, 16000); 

    } else { 
     /* make layout visible */   
     volumeBar.setVisibility(View.VISIBLE); 
     topBar.setVisibility(View.VISIBLE); 
     audioControllView.setVisibility(View.VISIBLE); 

     showhideControllers(1); 
    } 

} 

    @Override 
public void onUserInteraction() { 
    super.onUserInteraction(); 
    showhideControllers(2); 
} 

)、Iは、(1)showhideControllersを呼び出すことにより、タイマーを開始しています;. 今、画面をクリックするとレイアウトが再び現れ、タイマーがリセットされます。しかし、私がランダムに画面をクリックし続けると、クリックごとにタイマーがリセットされず、レイアウトは16秒後に消えます。 私は何が間違っているのか教えてもらえますか?

答えて

11

ご迷惑をおかけして申し訳ありません。しかし、ここに解決策があります。私も同様の問題を抱えていた。だからあなたのコードに以下の変更を加えました。これを試してみてください。

private Runnable hideControllerThread = new Runnable() { 

    public void run() { 
      volumeBar.setVisibility(View.GONE); 
      audioControllView.setVisibility(View.GONE); 
      topBar.setVisibility(View.GONE); 
    } 
}; 


public void hideControllers() { 
     hidehandler.postDelayed(hideControllerThread, 15000); 
} 

public void showControllers() { 
     volumeBar.setVisibility(View.VISIBLE); 
     topBar.setVisibility(View.VISIBLE); 
     audioControllView.setVisibility(View.VISIBLE); 
     hidehandler.removeCallbacks(hideControllerThread); 
     hideControllers(); 
} 

@Override 
public void onUserInteraction() { 
     super.onUserInteraction(); 

     if (audioControllView.getVisibility() == View.VISIBLE) { 
      hidehandler.removeCallbacks(hideControllerThread); 
      hideControllers(); 
     } else { 
      showControllers(); 
     } 
} 
+0

こんにちはこれは動作しています...ありがとうございます.. – curiousguy

+0

お返事ありがとうございます。 – jyotiprakash

関連する問題