Using alpha as the propertyName of the objectAnimator does nothing at all. The objectAnimator is connected to a path inside the vector.
fading_animator.xml:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:duration="700"
android:propertyName="alpha"
android:valueFrom="1"
android:valueTo="0"
android:valueType="floatType"
android:repeatCount="infinite"
android:repeatMode="restart"/>
</set>
animated_vector.xml:
<animated-vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/vector_drawable">
<target
android:name="pathTarget"
android:animation="#animator/fading_animator"/>
</animated-vector>
When trying to animate the alpha of a path, you have to use either fillAlpha or strokeAlpha. Similarly, scaleX and scaleY will not work on a path but it will work on a group inside the vector.
Related
I am working on a very basic animation which animates a ball ImageView from left to right within a container. The animation works great, but when it animates to 100%p, the ball gets cut out of the container view.
The ImageView that animates is a static 50dp.
Is there any way to do something like 100%p-50dp to prevent the ball from clipping out of the container?
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_decelerate_interpolator"
android:fillAfter="true"
>
<!--animate the ball-->
<translate
android:fromXDelta="0%p"
android:toXDelta="100%p"
android:duration="900"
android:repeatMode="reverse"
android:repeatCount="infinite"
/>
</set>
a bit hacky but here it 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"
android:fillAfter="true"
>
<!--animate the ball-->
<translate
android:fromXDelta="0"
android:toXDelta="-100%"
android:duration="900"
android:repeatMode="reverse"
android:repeatCount="infinite"
/>
<translate
android:fromXDelta="0%"
android:toXDelta="100%p"
android:duration="900"
android:repeatMode="reverse"
android:repeatCount="infinite"
/>
</set>
basically what we do is to translate the ball both by the parent size and by its own size at the same time
Declaring animation like that will internally use Animation API. It's suggested to refrain from using Animation API if possible. I'm not sure whether it's possible to achieve that using by xml only, that's why I would suggest using Animator API instead, particularly ViewPropertyAnimator.
ball.setOnClickListener {
val animateToX = if (it.translationX == 0F) container.width - ball.width.toFloat()
else 0F
it.animate().translationX(animateToX)
}
This is the output:
To translation in x position (Left to right) upto a perticular distance, here 200f is the tranlation distance.
val animator = ObjectAnimator.ofFloat(star, View.TRANSLATION_X, 200f)
animator.start()
To show a smooth or slow tranlation use duration property (by default duration is 300).
val animator = ObjectAnimator.ofFloat(star, View.TRANSLATION_X, 200f)
animator.duration = 1000
animator.start()
To tranlate back to the same position use repetCout and repeatMode.
val animator = ObjectAnimator.ofFloat(star, View.TRANSLATION_X, 200f)
animator.duration = 1000
animator.repeatCount = 1
animator.repeatMode = ObjectAnimator.REVERSE
animator.start()
Left to Right Animation
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:interpolator="#android:anim/linear_interpolator">
<translate
android:duration="800"
android:fromXDelta="0%p"
android:toXDelta="75%p" />
</set>
Hope it will help you.
I'm trying to make a flipping animation in Android.
I am using this code:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Set alpha to 0 before animation -->
<objectAnimator
android:valueFrom="1.0"
android:valueTo="0.0"
android:propertyName="alpha"
android:duration="0"/>
<!-- Rotate -->
<objectAnimator
android:valueFrom="180"
android:valueTo="0"
android:propertyName="rotationY"
android:interpolator="#android:interpolator/accelerate_decelerate"
android:duration="#integer/card_flip_time_full"/>
<!-- Half-way through the rotation set the alpha to 1 -->
<objectAnimator
android:valueFrom="0.0"
android:valueTo="1.0"
android:propertyName="alpha"
android:startOffset="#integer/card_flip_time_half"
android:duration="1"/>
</set>
However, I want it to flip from top to bottom. Something like this:
How do I do this?
You can do it programmatically. Here is the C# from Xamarin. Can't test the Java right now but it will be very similar.
ImageView block = FindViewById<ImageView>(Resource.Id.imgBlock);
ObjectAnimator blockSpin = ObjectAnimator.OfFloat(block, "rotationX", 0, 360);
imageCard.PivotX = 0.5f; //so it spins on center
float scale = metrics.Density;
imageCard.SetCameraDistance(8000*scale);
/*Set camera distance as required to avoid distortion.
Multiplying by scale keeps distance the same across devices. */
blockSpin.SetDuration(500);
blockSpin.Start();
How to set pivotX to right edge in xml. In res/anim it is possible by setting the value to "100%", but how it make in "res/animator" ?
res/animator/slide.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:propertyName="scaleX"
android:valueFrom="0.f"
android:valueTo="1.f"
android:duration="#integer/durationAnimate"
android:interpolator="#android:interpolator/accelerate_decelerate" />
<objectAnimator
android:duration="500"
android:propertyName="pivotY"
android:valueFrom="1.0"
android:valueTo="1.0"
android:valueType="floatType"/>
</set>
I need it in animator because, I make picture browser when there is random animation.
Animation implementation by:
getSupportFragmentManager()
.beginTransaction()
.setCustomAnimations(R.anim.slide_right_in, R.anim.slide_right_out)
.replace(R.id.mainActivityNew_fragmentAnimate, FotoFragment.newInstance(itemsController.nextItem()))
.commit();
In res/anim/... can not rotate fragment in axis (x or y), therefore, I would prefer to accomplish in res/animator/.... Unfortunately, I can in that make one type of animation and in that the second type of animation /
hi i have 2 views that i want to have zig zag up and off the screen. ive tried using object animators like this
float 1
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/decelerate_interpolator"
android:ordering="sequentially" >
<objectAnimator
android:duration="6000"
android:propertyName="y"
android:repeatCount="0"
android:valueFrom="1500"
android:valueTo="-1000"
android:valueType="floatType" />
</set>
and float 2
<objectAnimator
android:duration="3000"
android:propertyName="x"
android:repeatCount="1"
android:repeatMode="reverse"
android:valueFrom="-250"
android:valueType="floatType"
android:valueTo="50" />
<set
android:duration="3000"
android:propertyName="x"
android:repeatCount="1"
android:repeatMode="reverse"
android:valueFrom="-250"
android:valueTo="50"
android:valueType="floatType" />
</set>
but the results are varied, ie works on tablets but not smaller screens,
I've changed the code to do this programmatically and all it does is slightly change the way I goes up the screen all I want is both balloons to go up the screen at the moment it works beautifully on my tablet but on smaller screens it only shows one balloon. Been struggling on this a while now all views are laid out in XML and are hidden until needed I found there was a way of using fractions in my from and to values but apparently its deprecated any suggestions for a total n00b like me?
Have you tried creating your own custom interpolator, it basically defines how your animation is going to behave with respect to time, for example accelerate interpolator when used with lets say translate animation, it will accelerate your view, so you might have to create a custom interpolator, that will define your zig zag path, along with translate animation. you can read from here :
Tutorial on Interpolators
I checked out the transition animation that comes with API code and i found animation zoom_enter and zoom_exit in which activity 1 sinks IN to show activity 2. I need the other way round. I need activity 2 to zoom out from inside and come on top. (I hope you are getting me). This type of animation is the same on iphone screen transition.
The code below is what i have for the effect that i don't need.
Here is the code for zoom_enter.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/decelerate_interpolator">
<scale android:fromXScale="2.0" android:toXScale="1.0"
android:fromYScale="2.0" android:toYScale="1.0"
android:pivotX="50%p" android:pivotY="50%p"
android:duration="#android:integer/config_mediumAnimTime" />
</set>
And here is the code for zoom_exit.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/decelerate_interpolator"
android:zAdjustment="top">
<scale android:fromXScale="1.0" android:toXScale=".5"
android:fromYScale="1.0" android:toYScale=".5"
android:pivotX="50%p" android:pivotY="50%p"
android:duration="#android:integer/config_mediumAnimTime" />
<alpha android:fromAlpha="1.0" android:toAlpha="0"
android:duration="#android:integer/config_mediumAnimTime"/>
</set>
Then right after startActivity i call the method below:
overridePendingTransition(R.anim.zoom_enter, R.anim.zoom_exit);
Can anyone suggest how i can make changes to the above files to have the screen transition i explained?
Try this in zoom_enter.xml and remove animations from zoom_exit.xml. You will see better effects.
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/decelerate_interpolator">
<scale android:fromXScale="0.0" android:toXScale="1.0"
android:fromYScale="0.0" android:toYScale="1.0"
android:pivotX="50%p" android:pivotY="50%p"
android:duration="#android:integer/config_mediumAnimTime" />
</set>
Hope this helps.
overridePendingTransition(zoom_enter_new, zoom_exit_actual);
First param is for the incoming Activity (so the new)
Second param is for the outgoing Activity (the actual)
So if you want to make the same effect of the video where seems that
the actual activity is hide instantly than second param need to be set to 0 (means no animation)
overridePendingTransition(zoom_enter_new, 0);
And for making the new activity zoomin like the video this is the anim xml resource explained (zoom_enter_new.xml in res/anim/ dir)
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_decelerate_interpolator">
<!--scale view fromX fromY are the starting point (.5 is 50% of scale, )-->
<!--scale view toX and toY are the final state (1 is 100%)-->
<!--pivot is the center of animation, so in your case the zoomin on the video is from the exact center (50% pivot x, 50% pivot Y)-->
<scale android:fromXScale=".5" android:toXScale="1"
android:fromYScale=".5" android:toYScale="1"
android:pivotX="50%p" android:pivotY="50%p"
android:duration="#android:integer/config_longAnimTime" />
<!-- alpha animation is made at the same time of scale animation, and for me make a better and smooth result, alpha 0 is full trasparent, 1 is the normal state. The final alpha state of the activity after this animation is 1, so pay attention toAlpha must be 1 if you don't want glitch-->
<alpha android:fromAlpha="0.5" android:toAlpha="1"
android:duration="#android:integer/config_longAnimTime"/>
</set>
overridePendingTransition(R.anim.zoom_enter_new, 0);
Tobia