Create a layout with animation after clicking a button on Android

I am trying to implement a simple animation effect for the login screen.

Here is the script

1: By default, the text and login button will be displayed.

2: After pressing the login button, the picture above will appear. This layout will prompt the user to enter their username and password.

I can make an animation that overlays from one parent to another. In this case, I am looking for an animation that appears without leaving it.

+6
source share
2 answers

Install invisible to your layout first.
Set the 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 the 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 must edit the values ​​in slide_down.xml and slide_up.xml until you get a favorable result. For example, change android:fromYDelta="500" to android:fromYDelta="700"

+17
source

Check out this guide for some basic animations you can customize for your needs.

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

+2
source

All Articles