Make a layout appear with animation after button click in Android

后端 未结 2 658
眼角桃花
眼角桃花 2021-02-09 13:35

I\'m trying to implement a simple animation effect for login screen.

Here\'s the scenario,

1: Some text and a login button will be displayed by

2条回答
  •  再見小時候
    2021-02-09 14:20

    First set invisible to your layout.
    Set animation to slideUp and slideDown.

       final LinearLayout layout = (LinearLayout)findViewById(R.id.yourlayout);
    
       button.setOnClickListener(new OnClickListener(){
    
            @Override
            public void onClick(View arg0) {
                Animation slideUp = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_up);
                Animation slideDown = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_down);
    
                if(layout.getVisibility()==View.INVISIBLE){
    
                    layout.startAnimation(slideUp);
                    layout.setVisibility(View.VISIBLE);
            }
        });
    

    slide_up.xml (create in res/anim directory)

      
        
    
    

    slide_down.xml

      
        
    
    

    Note: You should edit values in slide_down.xml and slide_up.xml until get favorable result.
    for example:change android:fromYDelta="500" to android:fromYDelta="700"

提交回复
热议问题