Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a layout appear with animation after button click in Android

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 default.

2: After clicking the login button a new frame layout will appear from bottom to top. This layout will prompt user to enter their username and password.

I can make an animation which will overlay from one parent to another. In this scenario, I'm looking for an animation that will appear without leaving the activity.

like image 406
Falling Into Infinity Avatar asked Jan 21 '14 14:01

Falling Into Infinity


People also ask

What is transition animation in android?

Animation by Transition is an object (View) properties change based on object location on display and set effect. Since Transition has appeared in Android (4.4 KitKat version) there's a conception of Scene, and the changing between scenes is called Transition.


2 Answers

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)

<set xmlns:android="http://schemas.android.com/apk/res/android">  
    <translate android:fromXDelta="0" android:fromYDelta="500" android:duration="500"/>
</set>

slide_down.xml

<set xmlns:android="http://schemas.android.com/apk/res/android">  
    <translate android:fromXDelta="0" android:fromYDelta="0" android:toYDelta="500" android:duration="500"/>
</set>

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"

like image 131
Amir Avatar answered Oct 20 '22 22:10

Amir


Check out this tutorial, it explains some basic animations which you can customize for your need.

http://www.androidhive.info/2013/06/android-working-with-xml-animations/

like image 45
Bri6ko Avatar answered Oct 20 '22 20:10

Bri6ko