animating registration page android - android

I want to add animation to my registration page. I have 6 EditTexts and I want them to come one by one from right to left. I'm new to android, someone help me please.
Screenshot registration page

You can create your custom animation xmls and place inside anim folder inside resources folder:
left_swipe.xml
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:fromXDelta="100%"
android:toXDelta="0%" >
</translate>
right_swipe.xml
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:fromXDelta="-100%"
android:toXDelta="0%" >
</translate>
You can start animation like :
RightAnim = AnimationUtils.loadAnimation(Screen.this, R.anim.right_swipe);
ScreenAnimation.startAnimation(RightAnim );

Plz make sure your animation xml file under res>anim
This is for slide_in_left
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="-50%p" android:toXDelta="0"
android:duration="2500"/>
<alpha android:fromAlpha="0.0" android:toAlpha="1.0"
android:duration="#android:integer/config_mediumAnimTime" />
</set>
and this is for slide_in_right
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="50%p" android:toXDelta="0"
android:duration="2500"/>
<alpha android:fromAlpha="0.0" android:toAlpha="1.0"
android:duration="#android:integer/config_mediumAnimTime" />
</set>
in your java code
Animation a = AnimationUtils.loadAnimation(RegisterActivity.this, R.anim.slide_in_left);
a.reset();
etusername.clearAnimation();
etusername.startAnimation(a);
Animation b = AnimationUtils.loadAnimation(RegisterActivity.this, R.anim.slide_in_right);
b.reset();
etpassword.clearAnimation();
etpassword.startAnimation(b);

left to right animation:
leftToRight.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate android:fromXDelta="-100%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="700"/>
</set>
right to left animation:
rightToLeft
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="0%" android:toXDelta="100%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="700" />
</set>
write below code in your activity class
private Animation m_animationLeft;
private Animation m_animationRight;
m_animationLeft = AnimationUtils.loadAnimation(this, R.anim.leftToRight);
m_animationRight = AnimationUtils.loadAnimation(this, R.anim.rightToLeft);
editTextOne.startAnimation(m_animationLeft);
m_animationLeft.setAnimationListener(new AnimationListener()
{
#Override
public void onAnimationStart(Animation p_animation)
{
}
#Override
public void onAnimationRepeat(Animation p_animation)
{
}
#Override
public void onAnimationEnd(Animation p_animation)
{
// Start animation on another edittext . If you want to perform animation one by one edittext
}
});
}
}.start();

Related

How to hide layout with right to left translation

I want to hide a layout on click button with right to left animation. I have already added animation to same layout while appearing the view. Now I want to hide that view with animation.
//on appearing view
Animation anim = AnimationUtils.loadAnimation(this, R.anim.left_to_right);
mylayout.startAnimation(anim1);
Now I want to hide same layout with rigth to left animation. And then I want to set visibility GONE.
You can make a animation resource and using on your startActivity
Activity
Intent intent = new Intent(this, ActivityB.class);
startActivity(intent);
overridePendingTransition(R.anim.right_left_in, R.anim.right_left_out);
finish();
animation res----> ../anim/right_left_in.xml
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fromXDelta="100%p"
android:toXDelta="0%p">
</translate>
animation res----> ../anim/right_left_out.xml
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fromXDelta="0%p"
android:toXDelta="100%p">
</translate>
==========================
OTHERS ANIMATION
../anim/move_left_in_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fromXDelta="-100%p"
android:toXDelta="0%p">
</translate>
../anim/move_left_out_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fromXDelta="0%p"
android:toXDelta="-100%p">
</translate>
../anim/slid_in.xml
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="#android:integer/config_longAnimTime"
android:fromXDelta="100%p"
android:toXDelta="0%p">
</translate>
../anim/slid_out.xml
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="#android:integer/config_longAnimTime"
android:fromXDelta="0%p"
android:toXDelta="-100%p">
</translate>
../anim/zoom_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true" >
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="3"
android:toYScale="3" >
</scale>
</set>
You can make same XML for animation Right to left and then apply animation same as you did and add animation listener like below, and just set Visibility gone to your view in onAnimationEnd
anim .setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
}
#Override
public void onAnimationRepeat(Animation animation) {
}
});
Create "anim" Android resource directory below res folder :
Then create new anim file called slide_left_out.xml and write this code :
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:ordering="together"
android:duration="350">
<translate
android:fromXDelta="0"
android:toXDelta="-100%p"
android:fromYDelta="0"
android:toYDelta="50%p"/>
<scale
android:fromXScale="1"
android:toXScale="0.5"
android:fromYScale="1"
android:toYScale="0.5"/>
<alpha
android:fromAlpha="1"
android:toAlpha="0"/>
</set>
Then apply the animation to the view
Animation anim = AnimationUtils.loadAnimation(MainActivity.this, R.anim.slide_left_out);
mylayout.startAnimation(anim);

transition between activities overlapping content

I've implemented a transition between my activities, the problem is that when the transition occurs the content of the first activity is showing on the second one for a millisecond and then it disappears showing the content of the second activity, How can I get rid of that and smoothly show the second activity?
animation_enter:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate android:fromXDelta="0%" android:toXDelta="-100%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="200"
/>
</set>
animation_leave:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="100%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="200"
/>
</set>
And that is how I'm calling it:
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
TextView clienteId = (TextView) view.findViewById(R.id.pedidoID);
Intent intent = new Intent(getActivity(), PedidoDetalheActivity.class);
intent.putExtra("id_pedido", clienteId.getText()); // envia o id do pedido para a tela de detalhes
startActivity(intent);
getActivity().overridePendingTransition(R.anim.animation_enter, R.anim.animation_leave);
}
});
So for your animations to work you have to do the following:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate android:fromXDelta="100%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="200"
/>
</set>
This means that the activity will enter from left (100%) and will stop on the it's initial position (0%)
As for the leave animations:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="0%" android:toXDelta="-100%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="200"
/>
</set>
This means that the current visible activity will leave the screen from it's current position (0%) to the right (-100%)

Is there a way to slide between Activities without the black gap?

I'm trying to create an Android app, and switch between activities with a slide, when the previous activity slides out to the right, and the new activity comes in the left.
I can do somethibg like this, with:
Intent intent = new Intent(getContext(), NextActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.in_ltr, R.anim.out_ltr);
Where the in_ltr.xml is:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="#android:anim/accelerate_decelerate_interpolator">
<translate
android:fromXDelta="-100%p"
android:toXDelta="0"
android:duration="700"
/>
</set>
And the out_ltr.xml is:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="#android:anim/accelerate_decelerate_interpolator">
<translate
android:fromXDelta="0"
android:toXDelta="100%p"
android:duration="500"
/>
</set>
It's almost perfect, but a small black gap appers between the two activity during the animation. You can see it here on YouTube.
I've tried anything I found in the Google in the last hour, but nothing seems to remove that gap. Is it possible to remove that gap?
Thanks!
Try to set Alpha with translate effect....
Try This...
slide_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:interpolator/accelerate_cubic">
<translate
android:fromXDelta="0%"
android:toXDelta="100%"
android:duration="400" />
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.3"
android:duration="500" />
</set>
Add this two file in res/anim folder.
slide_in.xml
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="#android:integer/config_longAnimTime"
android:fromXDelta="100%p"
android:toXDelta="0%p">
</translate>
slide_out.xml
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="#android:integer/config_longAnimTime"
android:fromXDelta="0%p"
android:toXDelta="-100%p">
</translate>
And write the following code in onCreate() method of next activity that you pass through the Intent.
overridePendingTransition(r.anim.slide_in, R.anim.slide_out);
hope it will remove your space
Try this: create a RootActivity.java and extend it in your activity.
import android.app.Activity;
import android.os.Bundle;
public class RootActivity extends Activity {
int onStartCount = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
onStartCount = 1;
if (savedInstanceState == null) // 1st time
{
this.overridePendingTransition(R.anim.anim_slide_in_left,
R.anim.anim_slide_out_left);
} else // already created so reverse animation
{
onStartCount = 2;
}
}
#Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
if (onStartCount > 1) {
this.overridePendingTransition(R.anim.anim_slide_in_right,
R.anim.anim_slide_out_right);
} else if (onStartCount == 1) {
onStartCount++;
}
}
}
add these animations to anim folder:
anim_slide_in_left.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="600"
android:fromXDelta="100%"
android:toXDelta="0%" >
</translate>
</set>
anim_slide_in_right.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="600"
android:fromXDelta="-100%"
android:toXDelta="0%" >
</translate>
</set>
anim_slide_out_right.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="600"
android:fromXDelta="0%"
android:toXDelta="100%" >
</translate>
</set>
anim_slide_out_left.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="600"
android:fromXDelta="0%"
android:toXDelta="-100%" >
</translate>
</set>
Try to add below item into your AppTheme
<item name="android:windowIsTranslucent">true</item>
Sorry guys, I was very, very stupid.
I changed the duration to the same amount of time, and the gap disappeared.

Swipe Animation in Android

I want to slide from left to right (opposite right to left in this code below). My current task is running correctly on button click.
Here is the source:
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnopen = (Button)findViewById(R.id.btnWindowAnimation);
btnopen.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, SecondActivity.class);
Bundle bundle =ActivityOptions.makeCustomAnimation(getApplicationContext(), ` `R.anim.animation,R.anim.animation2).toBundle();
startActivity(i, bundle);
}
});
}
Here Animation 1:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="100%p"
android:toXDelta="0"
android:duration="500"/>
Here Animation 2:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0"
android:toXDelta="-50%p"
android:duration="500"/>
This is for left to right animation:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate android:fromXDelta="-100%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="700"/>
</set>
This is for right to left animation:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="0%" android:toXDelta="100%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="700" />
</set>
Check this link.
Here is the first answer:
<translate
android:fromXDelta="-100%"
android:toXDelta="0%"
android:duration="500"/>
</set>
And here is the second XML:
<translate
android:fromXDelta="0%"
android:toXDelta="100%"
android:duration="500" />
</set>

Animation between two Activities does not work

I am trying to do a slide animation between two Activities when then one starts the other,
public void onClick(View view) {
Intent intent = new Intent(TestAppActivity.this, SecondActivity.class);
startActivityForResult(intent, 1);
TestAppActivity.this.overridePendingTransition(R.anim.animation_enter, R.anim.animation_leave);
finish();
}
There is no animation at all. The xmls are, for enter:
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="-100%"
android:toXDelta="0%"
android:fromYDelta="0%"
android:toYDelta="0%"
android:duration="3000" />
And for leave:
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="0%"
android:toXDelta="100%"
android:fromYDelta="0%"
android:toYDelta="0%"
android:duration="3000" />
I can see what is gong wrong here. Using Android 2.3.3. Thanks.
Put the overridePendingTransition(R.anim.animation_enter, R.anim.animation_leave); after finish();.
To do an animation where the first activity go to the left and the second activity enters from the right :
slide_out_left.xml :
<?xml version="1.0" encoding="utf-8"?>
<!--
Animation : Perform animation : Out - Direction : Left
-->
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="400"
android:fromXDelta="0"
android:toXDelta="-100%p" />
</set>
slide_in_right.xml :
<?xml version="1.0" encoding="utf-8"?>
<!--
Animation : Perform animation : In - Direction : Right
-->
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="400"
android:fromXDelta="100%p"
android:toXDelta="0" />
</set>
Note : you can change android:duration if you want.
And you have to add this code :
public void onClick(View view) {
Intent intent = new Intent(TestAppActivity.this, SecondActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
finish();
}

Categories

Resources