如何使用按钮延迟充气

时间:2013-01-30 17:48:01

标签: java android

嗯,我是一个新词,我试图延迟膨胀,因为当你按下一个按钮时,其他按钮中的动画也会发生,而且也会膨胀。

但你看不到动画,因为膨胀很快就会出现,所以我想延迟2000ms的膨胀,这样你就可以先看到动画,然后看到膨胀中的信息。

我使用相同的按钮来调用动画和充气。

这是我的代码:

 case R.id.btnsalud:

    //This is the code for animations   

        //This is the loader for all the animations that is used for the button
        {final Animation animBounceForSalud = AnimationUtils.loadAnimation(this, R.anim.bounce);
        final Animation animBounceForSalud1 = AnimationUtils.loadAnimation(this, R.anim.bounce1);
        //This object is the objects (buttons) whom is applied the animation
        final Button animSalud = (Button)findViewById(R.id.btnobra);
        final Button animSalud1 = (Button)findViewById(R.id.btnprotesta);
        //This object (button) is the one which applies the animation to the other buttons
        Button btnBounceSalud = (Button)findViewById(R.id.btnsalud);      
    animSalud.startAnimation(animBounceForSalud);
    animSalud1.startAnimation(animBounceForSalud1);
    animSalud.setVisibility(500);
    animSalud1.setVisibility(500);}



    //This is the code for inflate  
    //Check if the Layout already exists
    LinearLayout hiddenLayout1 = (LinearLayout)findViewById(R.id.hiddenLayout);
    if((hiddenLayout1 == null)){
        //Right here is where you can defined in which layout is going to 
        //inflate the hidden layout
        LinearLayout myLayout = (LinearLayout)findViewById(R.id.inflateposition0);
        View hiddenInfo = getLayoutInflater().inflate(R.layout.salud, myLayout, false);
        myLayout.addView(hiddenInfo);

    }

    break;

答案是任何答案:D

2 个答案:

答案 0 :(得分:0)

您应该为动画设置一个侦听器(http://developer.android.com/reference/android/view/animation/Animation.html#setAnimationListener(android.view.animation.Animation.AnimationListener)),并且仅在侦听器报告动画完成时添加视图。

答案 1 :(得分:0)

您可以在动画定义中设置持续时间参数,以修复动画应该有多长。在Java中有setDuration(time)方法,并且在XML中定义动画时有android:duration属性。 http://developer.android.com/guide/topics/resources/animation-resource.html