显示延迟Android Java的按钮

fel*_*gga 5 animation android

我想为我的程序创建一些简单的动画.有4个隐形按钮,我想要的是当程序启动时,那些按钮会延迟显示.

显示按钮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) {
 }
Run Code Online (Sandbox Code Playgroud)

有人可以帮帮我吗?

nha*_*man 9

使用处理程序:

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
}
Run Code Online (Sandbox Code Playgroud)