I'm a beginnner in Xamarin Android programming as well as in Android programming in general. I successfully run the following code with expected effect:
//in the context of the main Activity
StartActivity(someIntent);
OverridePendingTransition(Android.Resource.Animation.SlideInLeft,
Android.Resource.Animation.SlideOutRight);
Now I would like to create my own animations for sliding from left and sliding out from right using XML declaration. I put my XML files under the anim folder with names slideInLeft.xml and slideOutRight.xml respectively. Here are the files' content:
slideInLeft.xml:
<?xml version="1.0" encoding="utf-8" ?>
<translate xmlns:android="http://schemes.android.com/apk/res/android"
android:duration="300"
android:fromXDelta="-100%"
android:toXDelta="0%">
</translate>
slideOutRight.xml:
<?xml version="1.0" encoding="utf-8" ?>
<translate xmlns:android="http://schemes.android.com/apk/res/android"
android:duration="350"
android:fromXDelta="0%"
android:toXDelta="100%">
</translate>
Now the code is just simply changed to this:
//in the context of the main Activity
StartActivity(someIntent);
OverridePendingTransition(Resource.Animation.SlideInLeft,
Resource.Animation.SlideOutRight);
But the animation is not working, the new Activity is just shown after a short of delay (looks like being equal the duration of sliding in which is 300ms).
This is confusing me. I don't know why and how to make this work.
Try changing your xml files to:
slideInLeft
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="-100%p" android:toXDelta="0"
android:duration="350"/>
</set>
AND
slideOutRight
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:toXDelta="100%p"
android:duration="350"/>
</set>
This should work.
You try to set duration more longer to see the transition :)
slideInLeft.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<translate android:duration="5000"
android:fromXDelta="-100%"
android:toXDelta="0%"/>
<alpha android:duration="5000"
android:fromAlpha="0.0"
android:toAlpha="1.0" />
</set>
slideOutRight.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<translate android:duration="5000"
android:fromXDelta="0%"
android:toXDelta="100%"/>
<alpha android:duration="5000"
android:fromAlpha="1.0"
android:toAlpha="0.0" />
</set>
Related
I am creating an Android application. I want to open the new activity with zoom in transition. I have some buttons in my current activity. When I click one button new activity will open from the button's position. I try to use the following code. But no transition will appear. I am using the following xml and java codes.
zoom_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="800"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="70%"
android:pivotY="70%"
android:toXScale="3"
android:toYScale="3" >
</scale>
</set>
and zoom_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="800"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="70%"
android:pivotY="70%"
android:toXScale="0.5"
android:toYScale="0.5" >
</scale>
</set>
And in my java code I call it like
overridePendingTransition(R.anim.zoom_in,R.anim.zoom_out);
With these code no effect will appear. Could someone please help me to finds out what is the issue?
Try to add the attribute: android:fillAfter="true"
Like this:
<?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>
place both animation xml files zoom_in.xml and zoom_out.xml in res/anim
directory and start animation like this :
overridePendingTransition(R.anim.zoom_in,R.anim.zoom_out);
I have two indicators, each need to be invisible to start. I want them to be visible after animating in, how do i do this? Right now they animate in then disappear, here is the code:
indicator.setVisibility(View.INVISIBLE);
indicator2.setVisibility(View.INVISIBLE);
Animation fadeInAnimation = AnimationUtils.loadAnimation(getActivity(), R.anim.fade_in_view);
indicator.startAnimation(fadeInAnimation);
indicator2.startAnimation(fadeInAnimation);
My xml is:
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="#android:anim/accelerate_interpolator"
android:duration="1500"
android:repeatCount="0" />
</set>
Try doing this: fadeInAnimation.setFillAfter(true)
or
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="#android:anim/accelerate_interpolator"
android:duration="1500"
android:repeatCount="0"
android:fillAfter="true"/>
</set>
I am trying to slide a fragment from let to right to get a sliding menu effect. But the fragment slides from bottom to up.
The ylocation is a button in center top of my activity.
newAddressFragment = new AddressFagment(AddressActivity.this,
ylocation);
AddressActivity.this
.getFragmentManager()
.beginTransaction()
.setCustomAnimations(R.anim.enter_from_left, R.anim.exit_from_bottom)
.addToBackStack(newAddressFragment.toString())
.replace(R.id.address_frame, newAddressFragment,
newAddressFragment.toString())
.commit();
enter_from_left.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<translate android:duration="5000" android:fromXDelta="-100%" android:toXDelta="0%"/>
<alpha android:duration="5000" android:fromAlpha="0.0" android:toAlpha="1.0" />
</set>
exit_to_left.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<translate android:duration="5000" android:fromXDelta="0%" android:toXDelta="-100%"/>
<alpha android:duration="5000" android:fromAlpha="1.0" android:toAlpha="0.0" />
</set>
After some workaround , the code that worked was :
getSupportFragmentManager()
.beginTransaction()
.setCustomAnimations(R.anim.enter_from_left, 0, 0,
R.anim.exit_to_left)
.add(R.id.dummy, new SliderMenuActivity())
.addToBackStack("animation").commit();
enter_from_left.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="#android:integer/config_mediumAnimTime">
<translate
android:fromXDelta="-100%p"
android:startOffset="25"
android:toXDelta="0" />
</set>
exit_to_left.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="#android:integer/config_mediumAnimTime">
<translate
android:fromXDelta="0"
android:startOffset="25"
android:toXDelta="-100%p"/>
</set>
Hope this helps !!
I'm trying to do a scale in/out animation for activity/framgent transition
here are the two animations :
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:interpolator="#android:anim/accelerate_decelerate_interpolator" >
<scale
android:fromXScale="80%"
android:fromYScale="80%"
android:toXScale="80%"
android:toYScale="80%" />
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.5" />
</set>
-
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:interpolator="#android:anim/accelerate_decelerate_interpolator" >
<translate
android:fromXDelta="100%"
android:fromYDelta="0"
android:toXDelta="0"
android:toYDelta="0" />
</set>
Use it like that :
overridePendingTransition(R.anim.slide_in_right, R.anim.slide_to_behind);
The problem is that the activity doesn't scale down in the center of the screen, it stick to the top/left of the screen
Any idea what wm i missing ? Or doing wrong ?
Add a pivot to your scale animation. Add this on your xml:
android:pivotX="50%"
android:pivotY="50%"
Your scale should look like:
<scale
android:fromXScale="100%"
android:fromYScale="100%"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="80%"
android:toYScale="80%" />
This animation isn't animating it just instantly disappears no matter what duration I set
here is the java code and xml
Java Code:
Animation shrink =AnimationUtils.loadAnimation(Page.this, R.anim.shrink);
deleteMe.startAnimation(shrink);
XML File:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:shareInterpolator="true"
android:interpolator="#android:anim/linear_interpolator"
android:duration="10000">
<scale
android:duration="10000"
android:fillAfter="true"
android:fromXScale="1.0"
android:toXScale="0" >
</scale>
<alpha
android:duration="10000"
android:fromAlpha="1.0"
android:toAlpha="0">
</alpha>
</set>
Specify android:interpolator attribute of set tag with the value you desired.
This interpolator just moves the object from the start point to the end point (or rotation) at a steady rate.
for ex::
android:interpolator="#android:anim/linear_interpolator"
In one of my app i write this code to move a block from left to right and its working well
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false" >
<rotate android:interpolator="#android:anim/accelerate_interpolator"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1500"
android:startOffset="1500"/>
<translate android:interpolator="#android:anim/accelerate_decelerate_interpolator"
android:fromYDelta="0"
android:toYDelta="-100%p"
android:duration="3000"/>
<translate android:interpolator="#android:anim/accelerate_decelerate_interpolator"
android:toXDelta="100%"
android:duration="1500"
android:startOffset="1500" />
</set>