2012-07-01 4 views
4

내 프로그램을위한 간단한 애니메이션을 만들고 싶습니다. 4 개의 보이지 않는 버튼이 있는데, 내가 원하는 것은 프로그램이 시작될 때입니다. 버튼이 지연되어 표시됩니다.지연 표시 버튼 Android Java

버튼 1 -> 버튼 2 -> 등을 표시합니다.

프로그램을 실행하면 모든 버튼이 동시에 나타납니다.

try { 
((Button) findViewById(R.id.f1)).setVisibility(View.VISIBLE); 
    Thread.sleep(1200); 
((Button) findViewById(R.id.f2)).setVisibility(View.VISIBLE); 
    Thread.sleep(1200); 
((Button) findViewById(R.id.f3)).setVisibility(View.VISIBLE); 
    Thread.sleep(1200); 
((Button) findViewById(R.id.f4)).setVisibility(View.VISIBLE); 
    Thread.sleep(1200); 
} catch (Exception e) { 
} 

누구든지 나를 도와 줄 수 있습니까?

답변

6

Handler를 사용

private Handler handler; 

private void showButtons(){ 
    handler = new Handler(); 

handler.postDelayed(new Runnable(){ 
    @Override 
    public void run(){ 
     ((Button) findViewById(R.id.f1)).setVisibility(View.VISIBLE); 
    } 
}, 1200); 

handler.postDelayed(new Runnable(){ 
    @Override 
    public void run(){ 
     ((Button) findViewById(R.id.f2)).setVisibility(View.VISIBLE); 
    } 
}, 2400); 

//etc 
} 
+0

그것을 임마! 감사합니다 – felangga

0

이이 질문과 관련이없는,하지만 당신은 (당신이 무엇을 같은) 메인 스레드를 잠 경우는 응용 프로그램이 정지 할 수

+0

Handler.PostDelayed does not main 메인 스레드 –

-2
use handler for your purpose 
handler is thread which only can be used for updating UI apart from UI thread. 

private Handler handler; 

private void showButtons(){ 
    handler = new Handler(); 

handler.postDelayed(new Runnable(){ 
    @Override 
    public void run(){ 
     ((Button) findViewById(R.id.f1)).setVisibility(View.VISIBLE); 
    } 
}, 1200); 

handler.postDelayed(new Runnable(){ 
    @Override 
    public void run(){ 
     ((Button) findViewById(R.id.f2)).setVisibility(View.VISIBLE); 
    } 
}, 2400); 

//etc 
} 


or u can use handler.sendEmptyMessage(int what); 
their u make a logic of vissibility and invissible 
+1

그냥 내 대답을 복사 했습니까? – nhaarman

+0

님의 답변이 Niek의 답변으로 변경되었습니다. – Vinayak